From ff90f939edf33c3a96e1851c8c2df4ec3646ca24 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Sat, 16 May 2015 00:06:55 +0200 Subject: [PATCH] Added 1 more test for emplace() --- test/optional_test_emplace.cpp | 48 ++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/test/optional_test_emplace.cpp b/test/optional_test_emplace.cpp index 9e7ed8a..0aa6674 100644 --- a/test/optional_test_emplace.cpp +++ b/test/optional_test_emplace.cpp @@ -157,18 +157,50 @@ 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 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) - test_emplace(); + test_emplace(); #endif #if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) - test_no_moves_on_emplacement(); + test_no_moves_on_emplacement(); #endif - test_clear_on_throw(); - test_no_assignment_on_emplacement(); - - return boost::report_errors(); + test_clear_on_throw(); + test_no_assignment_on_emplacement(); + no_rvalue_refs::test_emplace(); + + return boost::report_errors(); } - -