Skip to content

Commit

Permalink
Restore support for compilers without ref qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
akrzemi1 committed Oct 16, 2024
1 parent c8bd18d commit b2c7f93
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
13 changes: 10 additions & 3 deletions include/boost/none_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions include/boost/optional/detail/optional_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions include/boost/optional/detail/optional_swap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {} ;
Expand Down
68 changes: 33 additions & 35 deletions include/boost/optional/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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>
{};
Expand Down Expand Up @@ -922,61 +912,63 @@ 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() ;
else
throw_exception(bad_optional_access());
}

reference_type value() &
reference_type value() BOOST_OPTIONAL_REF_QUAL
{
if (this->is_initialized())
return this->get() ;
else
throw_exception(bad_optional_access());
}

reference_type_of_temporary_wrapper value() &&
template <class U>
value_type value_or ( U&& v ) BOOST_OPTIONAL_CONST_REF_QUAL
{
if (this->is_initialized())
return optional_detail::move(this->get()) ;
return get();
else
throw_exception(bad_optional_access());
return optional_detail::forward<U>(v);
}



template <class U>
value_type value_or ( U&& v ) const&
template <typename F>
value_type value_or_eval ( F f ) BOOST_OPTIONAL_CONST_REF_QUAL
{
if (this->is_initialized())
return get();
else
return optional_detail::forward<U>(v);
return f();
}

template <class U>
value_type value_or ( U&& v ) &&
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
reference_type_of_temporary_wrapper value() &&
{
if (this->is_initialized())
return optional_detail::move(get());
return optional_detail::move(this->get()) ;
else
return optional_detail::forward<U>(v);
throw_exception(bad_optional_access());
}

template <typename F>
value_type value_or_eval ( F f ) const&
template <class U>
value_type value_or ( U&& v ) &&
{
if (this->is_initialized())
return get();
return optional_detail::move(get());
else
return f();
return optional_detail::forward<U>(v);
}

template <typename F>
Expand All @@ -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());
Expand All @@ -998,14 +993,15 @@ 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());
else
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) &&
{
Expand All @@ -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());
Expand All @@ -1027,14 +1024,15 @@ 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());
else
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) &&
Expand All @@ -1044,7 +1042,7 @@ class optional
else
return none;
}

#endif

bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }

Expand Down

0 comments on commit b2c7f93

Please sign in to comment.