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,6 +157,39 @@ void test_no_assignment_on_emplacement()
|
||||
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()
|
||||
{
|
||||
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
@ -167,8 +200,7 @@ int main()
|
||||
#endif
|
||||
test_clear_on_throw();
|
||||
test_no_assignment_on_emplacement();
|
||||
no_rvalue_refs::test_emplace();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user