Restore support for compilers without ref qualifiers

This commit is contained in:
Andrzej Krzemienski
2024-10-16 22:51:06 +02:00
parent c8bd18d6de
commit b2c7f93ead
4 changed files with 60 additions and 46 deletions

View File

@ -14,11 +14,18 @@
#define BOOST_NONE_T_17SEP2003_HPP #define BOOST_NONE_T_17SEP2003_HPP
#include <boost/config.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) \ #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_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) || 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 #endif

View File

@ -16,7 +16,7 @@
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/config/workaround.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 # define BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
#endif #endif
@ -82,7 +82,7 @@
#endif // defined(__GNUC__) #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, // On some initial rvalue reference implementations GCC does it in a strange way,
// preferring perfect-forwarding constructor to implicit copy constructor. // preferring perfect-forwarding constructor to implicit copy constructor.
@ -132,4 +132,13 @@
#endif #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 #endif // header guard

View File

@ -91,7 +91,7 @@ struct swap_selector<false>
} // namespace optional_detail } // 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> template<class T>
struct optional_swap_should_use_default_constructor : boost::false_type {} ; struct optional_swap_should_use_default_constructor : boost::false_type {} ;

View File

@ -580,7 +580,6 @@ struct is_optional_constructible : boost::true_type
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
// for is_assignable // for is_assignable
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
// On some initial rvalue reference implementations GCC does it in a strange way, // On some initial rvalue reference implementations GCC does it in a strange way,
// preferring perfect-forwarding constructor to implicit copy constructor. // preferring perfect-forwarding constructor to implicit copy constructor.
@ -591,15 +590,6 @@ struct is_opt_assignable
#else #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> template <typename T, typename U>
struct is_opt_assignable : boost::is_convertible<U, T> 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, // Returns a reference to the value if this is initialized, otherwise,
// the behaviour is UNDEFINED // the behaviour is UNDEFINED
// No-throw // No-throw
reference_const_type operator *() const& { return this->get() ; } reference_const_type operator *() BOOST_OPTIONAL_CONST_REF_QUAL { return this->get() ; }
reference_type operator *() & { 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()) ; } 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()) if (this->is_initialized())
return this->get() ; return this->get() ;
@ -934,7 +927,7 @@ class optional
throw_exception(bad_optional_access()); throw_exception(bad_optional_access());
} }
reference_type value() & reference_type value() BOOST_OPTIONAL_REF_QUAL
{ {
if (this->is_initialized()) if (this->is_initialized())
return this->get() ; return this->get() ;
@ -942,6 +935,25 @@ class optional
throw_exception(bad_optional_access()); 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() && reference_type_of_temporary_wrapper value() &&
{ {
if (this->is_initialized()) if (this->is_initialized())
@ -950,17 +962,6 @@ class optional
throw_exception(bad_optional_access()); 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> template <class U>
value_type value_or ( U&& v ) && value_type value_or ( U&& v ) &&
{ {
@ -970,15 +971,6 @@ class optional
return optional_detail::forward<U>(v); 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> template <typename F>
value_type value_or_eval ( F f ) && value_type value_or_eval ( F f ) &&
{ {
@ -987,9 +979,12 @@ class optional
else else
return f(); return f();
} }
#endif
// Monadic interface
template <typename F> 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()) if (this->has_value())
return f(get()); return f(get());
@ -998,7 +993,7 @@ class optional
} }
template <typename F> 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()) if (this->has_value())
return f(get()); return f(get());
@ -1006,6 +1001,7 @@ class optional
return none; return none;
} }
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
template <typename F> template <typename F>
optional<typename optional_detail::result_of<F, reference_type_of_temporary_wrapper>::type> map(F f) && optional<typename optional_detail::result_of<F, reference_type_of_temporary_wrapper>::type> map(F f) &&
{ {
@ -1014,10 +1010,11 @@ class optional
else else
return none; return none;
} }
#endif
template <typename F> template <typename F>
optional<typename optional_detail::result_value_type<F, reference_type>::type> 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()) if (this->has_value())
return f(get()); return f(get());
@ -1027,7 +1024,7 @@ class optional
template <typename F> template <typename F>
optional<typename optional_detail::result_value_type<F, reference_const_type>::type> 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()) if (this->has_value())
return f(get()); return f(get());
@ -1035,6 +1032,7 @@ class optional
return none; return none;
} }
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
template <typename F> template <typename F>
optional<typename optional_detail::result_value_type<F, reference_type_of_temporary_wrapper>::type> optional<typename optional_detail::result_value_type<F, reference_type_of_temporary_wrapper>::type>
flat_map(F f) && flat_map(F f) &&
@ -1044,7 +1042,7 @@ class optional
else else
return none; return none;
} }
#endif
bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; } bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }