fixing bug in tests: not accounting for copy elision

This commit is contained in:
Andrzej Krzemienski
2015-01-16 14:18:44 +01:00
parent 67c7e21b4b
commit eed1b6ea33
3 changed files with 79 additions and 82 deletions
+14 -1
View File
@@ -46,9 +46,22 @@ int counting_oracle::copy_ctor_count = 0;
int counting_oracle::copy_assign_count = 0;
int counting_oracle::equals_count = 0;
int count_copy_ctors_on_copy() // checks if we have copy elision
{
counting_oracle::copy_ctor_count = 0;
counting_oracle c(1);
counting_oracle c2(c);
int ans = counting_oracle::copy_ctor_count;
counting_oracle::copy_ctor_count = 0;
counting_oracle::val_ctor_count = 0;
return ans;
}
// Test boost::tie() interoperability.
int main()
{
int copy_factor = count_copy_ctors_on_copy();
const std::pair<counting_oracle, counting_oracle> pair(1, 2);
boost::optional<counting_oracle> o1, o2;
boost::tie(o1, o2) = pair;
@@ -57,7 +70,7 @@ int main()
BOOST_TEST(o2);
BOOST_TEST(*o1 == counting_oracle(1));
BOOST_TEST(*o2 == counting_oracle(2));
BOOST_TEST_EQ(2, counting_oracle::copy_ctor_count);
BOOST_TEST_EQ(2 * copy_factor, counting_oracle::copy_ctor_count);
BOOST_TEST_EQ(0, counting_oracle::copy_assign_count);
BOOST_TEST_EQ(0, counting_oracle::default_ctor_count);