mirror of
https://github.com/boostorg/optional.git
synced 2025-07-30 20:47:18 +02:00
More tests on emplace()
This commit is contained in:
@ -58,21 +58,6 @@ private:
|
|||||||
void operator=(Guard const&);
|
void operator=(Guard const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Thrower
|
|
||||||
{
|
|
||||||
Thrower(bool throw_) { if (throw_) throw int(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Thrower(Thrower const&);
|
|
||||||
Thrower(Thrower&&);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ThrowOnMove
|
|
||||||
{
|
|
||||||
ThrowOnMove(ThrowOnMove&&) { throw int(); }
|
|
||||||
ThrowOnMove(ThrowOnMove const&) { throw int(); }
|
|
||||||
ThrowOnMove(int){}
|
|
||||||
};
|
|
||||||
|
|
||||||
void test_emplace()
|
void test_emplace()
|
||||||
{
|
{
|
||||||
@ -115,6 +100,44 @@ void test_emplace()
|
|||||||
BOOST_CHECK(7 == o->which_ctor);
|
BOOST_CHECK(7 == o->which_ctor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
|
|
||||||
|
|
||||||
|
struct ThrowOnMove
|
||||||
|
{
|
||||||
|
ThrowOnMove(ThrowOnMove&&) { throw int(); }
|
||||||
|
ThrowOnMove(ThrowOnMove const&) { throw int(); }
|
||||||
|
ThrowOnMove(int){}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void test_no_moves_on_emplacement()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
optional<ThrowOnMove> o;
|
||||||
|
o.emplace(1);
|
||||||
|
BOOST_CHECK(o);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
BOOST_CHECK(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct Thrower
|
||||||
|
{
|
||||||
|
Thrower(bool throw_) { if (throw_) throw int(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Thrower(Thrower const&);
|
||||||
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
|
Thrower(Thrower&&);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
void test_clear_on_throw()
|
void test_clear_on_throw()
|
||||||
{
|
{
|
||||||
optional<Thrower> ot;
|
optional<Thrower> ot;
|
||||||
@ -133,30 +156,27 @@ void test_clear_on_throw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_no_moves_on_emplacement()
|
void test_no_assignment_on_emplacement()
|
||||||
{
|
{
|
||||||
try {
|
optional<const std::string> os;
|
||||||
optional<ThrowOnMove> o;
|
BOOST_CHECK(!os);
|
||||||
o.emplace(1);
|
os.emplace("wow");
|
||||||
BOOST_CHECK(o);
|
BOOST_CHECK(os);
|
||||||
}
|
BOOST_CHECK(*os == "wow");
|
||||||
catch (...) {
|
|
||||||
BOOST_CHECK(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int test_main( int, char* [] )
|
int test_main( int, char* [] )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#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();
|
||||||
test_clear_on_throw();
|
#endif
|
||||||
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
test_no_moves_on_emplacement();
|
test_no_moves_on_emplacement();
|
||||||
#endif
|
#endif
|
||||||
|
test_clear_on_throw();
|
||||||
|
test_no_assignment_on_emplacement();
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user