mirror of
https://github.com/boostorg/optional.git
synced 2026-07-09 18:00:53 +02:00
fixing bug in tests: not accounting for copy elision
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user