mirror of
https://github.com/boostorg/optional.git
synced 2025-07-16 13:52:08 +02:00
Added 1 more test for emplace()
This commit is contained in:
@ -157,18 +157,50 @@ void test_no_assignment_on_emplacement()
|
|||||||
BOOST_TEST_EQ(*ot, "");
|
BOOST_TEST_EQ(*ot, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace no_rvalue_refs {
|
||||||
|
class Guard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int which_ctor;
|
||||||
|
Guard () : which_ctor(0) { }
|
||||||
|
Guard (std::string const&) : which_ctor(5) { }
|
||||||
|
Guard (std::string &) : which_ctor(6) { }
|
||||||
|
private:
|
||||||
|
Guard(Guard const&);
|
||||||
|
void operator=(Guard const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
void test_emplace()
|
||||||
|
{
|
||||||
|
const std::string cs;
|
||||||
|
std::string ms;
|
||||||
|
optional<Guard> o;
|
||||||
|
|
||||||
|
o.emplace();
|
||||||
|
BOOST_TEST(o);
|
||||||
|
BOOST_TEST(0 == o->which_ctor);
|
||||||
|
|
||||||
|
o.emplace(cs);
|
||||||
|
BOOST_TEST(o);
|
||||||
|
BOOST_TEST(5 == o->which_ctor);
|
||||||
|
|
||||||
|
o.emplace(ms);
|
||||||
|
BOOST_TEST(o);
|
||||||
|
BOOST_TEST(6 == o->which_ctor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||||
test_emplace();
|
test_emplace();
|
||||||
#endif
|
#endif
|
||||||
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
test_no_moves_on_emplacement();
|
test_no_moves_on_emplacement();
|
||||||
#endif
|
#endif
|
||||||
test_clear_on_throw();
|
test_clear_on_throw();
|
||||||
test_no_assignment_on_emplacement();
|
test_no_assignment_on_emplacement();
|
||||||
|
no_rvalue_refs::test_emplace();
|
||||||
return boost::report_errors();
|
|
||||||
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user