diff --git a/include/boost/none_t.hpp b/include/boost/none_t.hpp index 0f95128..1c8e076 100644 --- a/include/boost/none_t.hpp +++ b/include/boost/none_t.hpp @@ -14,11 +14,18 @@ #define BOOST_NONE_T_17SEP2003_HPP #include +#include -#if defined (BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_REF_QUALIFIERS) \ -|| defined(BOOST_NO_CXX11_LAMBDAS) || defined(BOOST_NO_CXX11_DECLTYPE_N3276) || defined(BOOST_NO_CXX11_NOEXCEPT) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_NO_CXX11_DEFAULTED_MOVES) || defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) +#if defined (BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \ +|| defined(BOOST_NO_CXX11_LAMBDAS) || defined(BOOST_NO_CXX11_DECLTYPE_N3276) \ +|| defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) \ +|| defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) || defined(BOOST_NO_CXX11_STATIC_ASSERT) -#error "Boost.Optional requires C++11 or later. If you have an older C++ version use Boost.Optional version 1.86 or earlier." +#error "Boost.Optional requires some C++11 features since version 1.87. If you have an older C++ version use Boost.Optional version 1.86 or earlier." + +#elif defined(BOOST_NO_CXX11_REF_QUALIFIERS) || defined(BOOST_NO_CXX11_NOEXCEPT) || defined(BOOST_NO_CXX11_DEFAULTED_MOVES) + +BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Optional 1.83 and will be removed in Boost.Optional 1.88.") #endif diff --git a/include/boost/optional/detail/optional_config.hpp b/include/boost/optional/detail/optional_config.hpp index 3e5e282..b7ccc3e 100644 --- a/include/boost/optional/detail/optional_config.hpp +++ b/include/boost/optional/detail/optional_config.hpp @@ -16,7 +16,7 @@ #include #include -#if (defined BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES) +#if (defined BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES) # define BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #endif @@ -82,7 +82,7 @@ #endif // defined(__GNUC__) -#if (defined __GNUC__) && (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) +#if (defined __GNUC__) // On some initial rvalue reference implementations GCC does it in a strange way, // preferring perfect-forwarding constructor to implicit copy constructor. @@ -132,4 +132,13 @@ #endif +#ifdef BOOST_NO_CXX11_REF_QUALIFIERS +# define BOOST_OPTIONAL_CONST_REF_QUAL const +# define BOOST_OPTIONAL_REF_QUAL +#else +# define BOOST_OPTIONAL_CONST_REF_QUAL const& +# define BOOST_OPTIONAL_REF_QUAL & +#endif + + #endif // header guard diff --git a/include/boost/optional/detail/optional_swap.hpp b/include/boost/optional/detail/optional_swap.hpp index 0c708c6..f1d301b 100644 --- a/include/boost/optional/detail/optional_swap.hpp +++ b/include/boost/optional/detail/optional_swap.hpp @@ -63,7 +63,7 @@ template <> struct swap_selector { template - static void optional_swap ( optional& x, optional& y ) + static void optional_swap ( optional& x, optional& y ) //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && BOOST_NOEXCEPT_EXPR(boost::core::invoke_swap(*x, *y))) { if (x) @@ -91,7 +91,7 @@ struct swap_selector } // namespace optional_detail -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION) +#if (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION) template struct optional_swap_should_use_default_constructor : boost::false_type {} ; diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 6aec3ce..afe42da 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -580,7 +580,6 @@ struct is_optional_constructible : boost::true_type #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) // for is_assignable -#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) // On some initial rvalue reference implementations GCC does it in a strange way, // preferring perfect-forwarding constructor to implicit copy constructor. @@ -591,15 +590,6 @@ struct is_opt_assignable #else -template -struct is_opt_assignable - : boost::conjunction, boost::is_assignable > -{}; - -#endif - -#else - template struct is_opt_assignable : boost::is_convertible {}; @@ -922,11 +912,14 @@ class optional // Returns a reference to the value if this is initialized, otherwise, // the behaviour is UNDEFINED // No-throw - reference_const_type operator *() const& { return this->get() ; } - reference_type operator *() & { return this->get() ; } + reference_const_type operator *() BOOST_OPTIONAL_CONST_REF_QUAL { return this->get() ; } + reference_type operator *() BOOST_OPTIONAL_REF_QUAL { return this->get() ; } + +#ifndef BOOST_NO_CXX11_REF_QUALIFIERS reference_type_of_temporary_wrapper operator *() && { return optional_detail::move(this->get()) ; } +#endif - reference_const_type value() const& + reference_const_type value() BOOST_OPTIONAL_CONST_REF_QUAL { if (this->is_initialized()) return this->get() ; @@ -934,7 +927,7 @@ class optional throw_exception(bad_optional_access()); } - reference_type value() & + reference_type value() BOOST_OPTIONAL_REF_QUAL { if (this->is_initialized()) return this->get() ; @@ -942,6 +935,25 @@ class optional throw_exception(bad_optional_access()); } + template + value_type value_or ( U&& v ) BOOST_OPTIONAL_CONST_REF_QUAL + { + if (this->is_initialized()) + return get(); + else + return optional_detail::forward(v); + } + + template + value_type value_or_eval ( F f ) BOOST_OPTIONAL_CONST_REF_QUAL + { + if (this->is_initialized()) + return get(); + else + return f(); + } + +#ifndef BOOST_NO_CXX11_REF_QUALIFIERS reference_type_of_temporary_wrapper value() && { if (this->is_initialized()) @@ -950,17 +962,6 @@ class optional throw_exception(bad_optional_access()); } - - - template - value_type value_or ( U&& v ) const& - { - if (this->is_initialized()) - return get(); - else - return optional_detail::forward(v); - } - template value_type value_or ( U&& v ) && { @@ -970,15 +971,6 @@ class optional return optional_detail::forward(v); } - template - value_type value_or_eval ( F f ) const& - { - if (this->is_initialized()) - return get(); - else - return f(); - } - template value_type value_or_eval ( F f ) && { @@ -987,9 +979,12 @@ class optional else return f(); } +#endif + +// Monadic interface template - optional::type> map(F f) & + optional::type> map(F f) BOOST_OPTIONAL_REF_QUAL { if (this->has_value()) return f(get()); @@ -998,7 +993,7 @@ class optional } template - optional::type> map(F f) const& + optional::type> map(F f) BOOST_OPTIONAL_CONST_REF_QUAL { if (this->has_value()) return f(get()); @@ -1006,6 +1001,7 @@ class optional return none; } +#ifndef BOOST_NO_CXX11_REF_QUALIFIERS template optional::type> map(F f) && { @@ -1014,10 +1010,11 @@ class optional else return none; } +#endif template optional::type> - flat_map(F f) & + flat_map(F f) BOOST_OPTIONAL_REF_QUAL { if (this->has_value()) return f(get()); @@ -1027,7 +1024,7 @@ class optional template optional::type> - flat_map(F f) const& + flat_map(F f) BOOST_OPTIONAL_CONST_REF_QUAL { if (this->has_value()) return f(get()); @@ -1035,6 +1032,7 @@ class optional return none; } +#ifndef BOOST_NO_CXX11_REF_QUALIFIERS template optional::type> flat_map(F f) && @@ -1044,7 +1042,7 @@ class optional else return none; } - +#endif bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }