diff --git a/include/boost/optional/detail/optional_reference_spec.hpp b/include/boost/optional/detail/optional_reference_spec.hpp index 35319cc..f64e581 100644 --- a/include/boost/optional/detail/optional_reference_spec.hpp +++ b/include/boost/optional/detail/optional_reference_spec.hpp @@ -82,7 +82,7 @@ public: void swap(optional& rhs) BOOST_NOEXCEPT { std::swap(ptr_, rhs.ptr_); } - T& get() const { BOOST_ASSERT(ptr_); return *ptr_; } + T& get() const { BOOST_ASSERT(ptr_); return *ptr_; } T* get_ptr() const BOOST_NOEXCEPT { return ptr_; } T* operator->() const { BOOST_ASSERT(ptr_); return ptr_; } @@ -133,25 +133,30 @@ public: #else // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template - optional(const U& v) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { } + optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { } template - optional(bool cond, const U& v) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {} + optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {} template - optional operator=(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); return *this; } + BOOST_DEDUCED_TYPENAME boost::enable_if, optional&>::type + operator=(U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); return *this; } template - void emplace(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); } + void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + { ptr_ = boost::addressof(v); } template - T& get_value_or(const U& v) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; } + T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + { return ptr_ ? *ptr_ : v; } template - T& value_or(const U& v) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; } + T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + { return ptr_ ? *ptr_ : v; } template - void reset(const U& v) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); } + void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + { ptr_ = boost::addressof(v); } #endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES }; diff --git a/test/optional_test_emplace.cpp b/test/optional_test_emplace.cpp index 0aa6674..1877a54 100644 --- a/test/optional_test_emplace.cpp +++ b/test/optional_test_emplace.cpp @@ -24,7 +24,7 @@ using boost::optional; using boost::none; -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) class Guard { @@ -90,7 +90,7 @@ void test_emplace() #endif -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) +#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) struct ThrowOnMove @@ -120,7 +120,7 @@ struct Thrower private: Thrower(Thrower const&); -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) +#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) Thrower(Thrower&&); #endif }; @@ -192,10 +192,10 @@ void test_emplace() int main() { -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) test_emplace(); #endif -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) +#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) test_no_moves_on_emplacement(); #endif test_clear_on_throw(); diff --git a/test/optional_test_move.cpp b/test/optional_test_move.cpp index 51aa970..1558c34 100644 --- a/test/optional_test_move.cpp +++ b/test/optional_test_move.cpp @@ -24,7 +24,7 @@ using boost::none; //#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT //#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES enum State { @@ -334,7 +334,7 @@ void test_optional_ref_to_movables() int main() { -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES test_move_ctor_from_U(); test_move_ctor_form_T(); test_move_ctor_from_optional_T(); diff --git a/test/optional_test_noexcept_move.cpp b/test/optional_test_noexcept_move.cpp index 9ce927f..0675844 100644 --- a/test/optional_test_noexcept_move.cpp +++ b/test/optional_test_noexcept_move.cpp @@ -20,7 +20,7 @@ using boost::optional; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #ifndef BOOST_NO_CXX11_NOEXCEPT // these 4 classes have different noexcept signatures in move operations @@ -106,7 +106,7 @@ void test_noexcept_optional_with_operator() // compile-time test } #endif // !defned BOOST_NO_CXX11_NOEXCEPT -#endif // !defined BOOST_NO_CXX11_RVALUE_REFERENCES +#endif // !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES int main() { diff --git a/test/optional_test_value_access.cpp b/test/optional_test_value_access.cpp index 1759588..47ec5cc 100644 --- a/test/optional_test_value_access.cpp +++ b/test/optional_test_value_access.cpp @@ -175,7 +175,7 @@ void test_const_move() } -#ifndef BOOST_NO_CXX11_REF_QUALIFIERS +#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) struct MoveOnly { explicit MoveOnly(int){}