mirror of
https://github.com/boostorg/optional.git
synced 2025-07-29 03:57:20 +02:00
Restore support for compilers without ref qualifiers
This commit is contained in:
@ -14,11 +14,18 @@
|
||||
#define BOOST_NONE_T_17SEP2003_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
#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
|
||||
|
@ -63,7 +63,7 @@ template <>
|
||||
struct swap_selector<false>
|
||||
{
|
||||
template <class T>
|
||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
//BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::core::invoke_swap(*x, *y)))
|
||||
{
|
||||
if (x)
|
||||
@ -91,7 +91,7 @@ struct swap_selector<false>
|
||||
|
||||
} // 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<class T>
|
||||
struct optional_swap_should_use_default_constructor : boost::false_type {} ;
|
||||
|
@ -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 <typename T, typename U>
|
||||
struct is_opt_assignable
|
||||
: boost::conjunction<boost::is_convertible<U, T>, boost::is_assignable<T&, U> >
|
||||
{};
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_opt_assignable : boost::is_convertible<U, T>
|
||||
{};
|
||||
@ -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 <class U>
|
||||
value_type value_or ( U&& v ) BOOST_OPTIONAL_CONST_REF_QUAL
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return get();
|
||||
else
|
||||
return optional_detail::forward<U>(v);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
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 <class U>
|
||||
value_type value_or ( U&& v ) const&
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return get();
|
||||
else
|
||||
return optional_detail::forward<U>(v);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
value_type value_or ( U&& v ) &&
|
||||
{
|
||||
@ -970,15 +971,6 @@ class optional
|
||||
return optional_detail::forward<U>(v);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
value_type value_or_eval ( F f ) const&
|
||||
{
|
||||
if (this->is_initialized())
|
||||
return get();
|
||||
else
|
||||
return f();
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
value_type value_or_eval ( F f ) &&
|
||||
{
|
||||
@ -987,9 +979,12 @@ class optional
|
||||
else
|
||||
return f();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Monadic interface
|
||||
|
||||
template <typename F>
|
||||
optional<typename optional_detail::result_of<F, reference_type>::type> map(F f) &
|
||||
optional<typename optional_detail::result_of<F, reference_type>::type> map(F f) BOOST_OPTIONAL_REF_QUAL
|
||||
{
|
||||
if (this->has_value())
|
||||
return f(get());
|
||||
@ -998,7 +993,7 @@ class optional
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
optional<typename optional_detail::result_of<F, reference_const_type>::type> map(F f) const&
|
||||
optional<typename optional_detail::result_of<F, reference_const_type>::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 <typename F>
|
||||
optional<typename optional_detail::result_of<F, reference_type_of_temporary_wrapper>::type> map(F f) &&
|
||||
{
|
||||
@ -1014,10 +1010,11 @@ class optional
|
||||
else
|
||||
return none;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename F>
|
||||
optional<typename optional_detail::result_value_type<F, reference_type>::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 <typename F>
|
||||
optional<typename optional_detail::result_value_type<F, reference_const_type>::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 <typename F>
|
||||
optional<typename optional_detail::result_value_type<F, reference_type_of_temporary_wrapper>::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() ; }
|
||||
|
||||
|
Reference in New Issue
Block a user