From dc7909db4a6cdfd7636ac593616b0b03b89c21e0 Mon Sep 17 00:00:00 2001 From: typenameTea Date: Wed, 18 Sep 2024 22:08:58 +0100 Subject: [PATCH] refactor: implementation tidy up C++11 is now the library minimum requirement, so clean up the interface by removing conditional compilation intended to support C++03 alongside C++11. --- .../optional_trivially_copyable_base.hpp | 242 +------- include/boost/optional/optional.hpp | 517 +----------------- 2 files changed, 2 insertions(+), 757 deletions(-) diff --git a/include/boost/optional/detail/optional_trivially_copyable_base.hpp b/include/boost/optional/detail/optional_trivially_copyable_base.hpp index 1d157cf..a8e0371 100644 --- a/include/boost/optional/detail/optional_trivially_copyable_base.hpp +++ b/include/boost/optional/detail/optional_trivially_copyable_base.hpp @@ -25,10 +25,8 @@ class tc_optional_base : public optional_tag protected: typedef T & reference_type ; typedef T const& reference_const_type ; -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES typedef T && rval_reference_type ; typedef T && reference_type_of_temporary_wrapper ; -#endif typedef T * pointer_type ; typedef T const* pointer_const_type ; typedef T const& argument_type ; @@ -51,9 +49,6 @@ class tc_optional_base : public optional_tag // tc_optional_base ( tc_optional_base const& ) = default; - -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES - template explicit tc_optional_base ( Expr&& expr, PtrExpr const* tag ) : @@ -62,20 +57,6 @@ class tc_optional_base : public optional_tag construct(boost::forward(expr),tag); } -#else - // This is used for both converting and in-place constructions. - // Derived classes use the 'tag' to select the appropriate - // implementation (the correct 'construct()' overload) - template - explicit tc_optional_base ( Expr const& expr, Expr const* tag ) - : - m_initialized(false) - { - construct(expr,tag); - } - -#endif - // tc_optional_base& operator= ( tc_optional_base const& ) = default; // ~tc_optional_base() = default; @@ -99,7 +80,6 @@ class tc_optional_base : public optional_tag m_initialized = rhs.is_initialized(); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // move-assigns from another _convertible_ optional (deep-moves from the rhs value) template void assign ( optional&& rhs ) @@ -109,7 +89,6 @@ class tc_optional_base : public optional_tag m_storage = static_cast(rhs.get()); m_initialized = rhs.is_initialized(); } -#endif void assign ( argument_type val ) { @@ -120,19 +99,11 @@ class tc_optional_base : public optional_tag #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template void assign_expr ( Expr&& expr, ExprPtr const* tag ) { construct(boost::forward(expr),tag); } -#else - template - void assign_expr ( Expr const& expr, Expr const* tag ) - { - construct(expr,tag); - } -#endif #endif @@ -162,7 +133,6 @@ class tc_optional_base : public optional_tag } -#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) // Constructs in-place // upon exception *this is always uninitialized template @@ -194,146 +164,9 @@ class tc_optional_base : public optional_tag if ( cond ) construct(in_place_init, boost::forward(args)...); } -#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) - template - void construct ( in_place_init_t, Arg&& arg ) - { - m_storage = value_type( boost::forward(arg) ); - m_initialized = true ; - } - - void construct ( in_place_init_t ) - { - m_storage = value_type(); - m_initialized = true ; - } - - template - void emplace_assign ( Arg&& arg ) - { - construct(in_place_init, boost::forward(arg)) ; - } - - void emplace_assign () - { - construct(in_place_init) ; - } - - template - explicit tc_optional_base ( in_place_init_t, Arg&& arg ) - : - m_initialized(false) - { - construct(in_place_init, boost::forward(arg)); - } - - explicit tc_optional_base ( in_place_init_t ) - : - m_initialized(false), m_storage() {} - - template - explicit tc_optional_base ( in_place_init_if_t, bool cond, Arg&& arg ) - : - m_initialized(false) - { - if ( cond ) - construct(in_place_init, boost::forward(arg)); - } - - explicit tc_optional_base ( in_place_init_if_t, bool cond ) - : - m_initialized(false) - { - if ( cond ) - construct(in_place_init); - } - -#else - - template - void construct ( in_place_init_t, const Arg& arg ) - { - m_storage = value_type( arg ); - m_initialized = true ; - } - - template - void construct ( in_place_init_t, Arg& arg ) - { - m_storage = value_type( arg ); - m_initialized = true ; - } - - void construct ( in_place_init_t ) - { - m_storage = value_type(); - m_initialized = true ; - } - - template - void emplace_assign ( const Arg& arg ) - { - construct(in_place_init, arg); - } - - template - void emplace_assign ( Arg& arg ) - { - construct(in_place_init, arg); - } - - void emplace_assign () - { - construct(in_place_init); - } - - template - explicit tc_optional_base ( in_place_init_t, const Arg& arg ) - : m_initialized(false) - { - construct(in_place_init, arg); - } - - template - explicit tc_optional_base ( in_place_init_t, Arg& arg ) - : m_initialized(false) - { - construct(in_place_init, arg); - } - - explicit tc_optional_base ( in_place_init_t ) - : m_initialized(false) - { - construct(in_place_init); - } - - template - explicit tc_optional_base ( in_place_init_if_t, bool cond, const Arg& arg ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init, arg); - } - - template - explicit tc_optional_base ( in_place_init_if_t, bool cond, Arg& arg ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init, arg); - } - - explicit tc_optional_base ( in_place_init_if_t, bool cond ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init); - } -#endif #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Constructs in-place using the given factory template void construct ( Expr&& factory, in_place_factory_base const* ) @@ -365,42 +198,8 @@ class tc_optional_base : public optional_tag construct(factory,tag); } -#else - // Constructs in-place using the given factory - template - void construct ( Expr const& factory, in_place_factory_base const* ) - { - boost_optional_detail::construct(factory, boost::addressof(m_storage)); - m_initialized = true ; - } - - // Constructs in-place using the given typed factory - template - void construct ( Expr const& factory, typed_in_place_factory_base const* ) - { - factory.apply(boost::addressof(m_storage)) ; - m_initialized = true ; - } - - template - void assign_expr_to_initialized ( Expr const& factory, in_place_factory_base const* tag ) - { - destroy(); - construct(factory,tag); - } - - // Constructs in-place using the given typed factory - template - void assign_expr_to_initialized ( Expr const& factory, typed_in_place_factory_base const* tag ) - { - destroy(); - construct(factory,tag); - } #endif -#endif - -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Constructs using any expression implicitly convertible to the single argument // of a one-argument T constructor. // Converting constructions of optional from optional uses this function with @@ -421,29 +220,6 @@ class tc_optional_base : public optional_tag { assign_value( boost::forward(expr) ); } -#else - // Constructs using any expression implicitly convertible to the single argument - // of a one-argument T constructor. - // Converting constructions of optional from optional uses this function with - // 'Expr' being of type 'U' and relying on a converting constructor of T from U. - template - void construct ( Expr const& expr, void const* ) - { - m_storage = value_type(expr) ; - m_initialized = true ; - } - - // Assigns using a form any expression implicitly convertible to the single argument - // of a T's assignment operator. - // Converting assignments of optional from optional uses this function with - // 'Expr' being of type 'U' and relying on a converting assignment of T from U. - template - void assign_expr_to_initialized ( Expr const& expr, void const* ) - { - assign_value(expr); - } - -#endif #ifdef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION // BCB5.64 (and probably lower versions) workaround. @@ -458,7 +234,7 @@ class tc_optional_base : public optional_tag // For VC<=70 compilers this workaround doesn't work because the compiler issues and error // instead of choosing the wrong overload // -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES + // Notice that 'Expr' will be optional or optional (but not tc_optional_base<..>) template void construct ( Expr&& expr, optional_tag const* ) @@ -471,26 +247,10 @@ class tc_optional_base : public optional_tag m_initialized = true ; } } -#else - // Notice that 'Expr' will be optional or optional (but not tc_optional_base<..>) - template - void construct ( Expr const& expr, optional_tag const* ) - { - if ( expr.is_initialized() ) - { - // An exception can be thrown here. - // It it happens, THIS will be left uninitialized. - m_storage = value_type(expr.get()) ; - m_initialized = true ; - } - } -#endif #endif // defined BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION void assign_value ( argument_type val ) { m_storage = val; } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES void assign_value ( rval_reference_type val ) { m_storage = static_cast(val); } -#endif void destroy() { diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index df3c8a3..b755d91 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -145,10 +145,8 @@ class optional_base : public optional_tag protected: typedef T & reference_type ; typedef T const& reference_const_type ; -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES typedef T && rval_reference_type ; typedef T && reference_type_of_temporary_wrapper ; -#endif typedef T * pointer_type ; typedef T const* pointer_const_type ; typedef T const& argument_type ; @@ -174,7 +172,6 @@ class optional_base : public optional_tag construct(val); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // move-construct an optional initialized from an rvalue-ref to 'val'. // Can throw if T::T(T&&) does optional_base ( init_value_tag, rval_reference_type val ) @@ -183,7 +180,6 @@ class optional_base : public optional_tag { construct( boost::move(val) ); } -#endif // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T const&) does @@ -195,7 +191,6 @@ class optional_base : public optional_tag construct(val); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates an optional initialized with 'move(val)' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T &&) does optional_base ( bool cond, rval_reference_type val ) @@ -205,7 +200,6 @@ class optional_base : public optional_tag if ( cond ) construct(boost::move(val)); } -#endif // Creates a deep copy of another optional // Can throw if T::T(T const&) does @@ -217,7 +211,6 @@ class optional_base : public optional_tag construct(rhs.get_impl()); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates a deep move of another optional // Can throw if T::T(T&&) does optional_base ( optional_base&& rhs ) @@ -228,9 +221,7 @@ class optional_base : public optional_tag if ( rhs.is_initialized() ) construct( boost::move(rhs.get_impl()) ); } -#endif -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template explicit optional_base ( Expr&& expr, PtrExpr const* tag ) @@ -240,34 +231,18 @@ class optional_base : public optional_tag construct(boost::forward(expr),tag); } -#else - // This is used for both converting and in-place constructions. - // Derived classes use the 'tag' to select the appropriate - // implementation (the correct 'construct()' overload) - template - explicit optional_base ( Expr const& expr, Expr const* tag ) - : - m_initialized(false) - { - construct(expr,tag); - } - -#endif - optional_base& operator= ( optional_base const& rhs ) { this->assign(rhs); return *this; } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES optional_base& operator= ( optional_base && rhs ) BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && ::boost::is_nothrow_move_assignable::value) { this->assign(static_cast(rhs)); return *this; } -#endif // No-throw (assuming T::~T() doesn't) ~optional_base() { destroy() ; } @@ -288,7 +263,6 @@ class optional_base : public optional_tag } } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Assigns from another optional (deep-moves the rhs value) void assign ( optional_base&& rhs ) { @@ -304,7 +278,6 @@ class optional_base : public optional_tag construct(boost::move(rhs.get_impl())); } } -#endif // Assigns from another _convertible_ optional (deep-copies the rhs value) template @@ -332,7 +305,6 @@ class optional_base : public optional_tag } } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // move-assigns from another _convertible_ optional (deep-moves from the rhs value) template void assign ( optional&& rhs ) @@ -350,7 +322,6 @@ class optional_base : public optional_tag construct(static_cast(rhs.get())); } } -#endif // Assigns from a T (deep-copies the rhs value) void assign ( argument_type val ) @@ -360,7 +331,6 @@ class optional_base : public optional_tag else construct(val); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Assigns from a T (deep-moves the rhs value) void assign ( rval_reference_type val ) { @@ -368,7 +338,6 @@ class optional_base : public optional_tag assign_value( boost::move(val) ); else construct( boost::move(val) ); } -#endif // Assigns from "none", destroying the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) @@ -376,7 +345,6 @@ class optional_base : public optional_tag #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template void assign_expr ( Expr&& expr, ExprPtr const* tag ) { @@ -384,15 +352,6 @@ class optional_base : public optional_tag assign_expr_to_initialized(boost::forward(expr),tag); else construct(boost::forward(expr),tag); } -#else - template - void assign_expr ( Expr const& expr, Expr const* tag ) - { - if (is_initialized()) - assign_expr_to_initialized(expr,tag); - else construct(expr,tag); - } -#endif #endif @@ -421,16 +380,13 @@ class optional_base : public optional_tag m_initialized = true ; } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES void construct ( rval_reference_type val ) { ::new (m_storage.address()) unqualified_value_type( boost::move(val) ) ; m_initialized = true ; } -#endif -#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) // Constructs in-place // upon exception *this is always uninitialized template @@ -463,154 +419,9 @@ class optional_base : public optional_tag if ( cond ) construct(in_place_init, boost::forward(args)...); } -#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) - template - void construct ( in_place_init_t, Arg&& arg ) - { - ::new (m_storage.address()) unqualified_value_type( boost::forward(arg) ); - m_initialized = true ; - } - - void construct ( in_place_init_t ) - { - ::new (m_storage.address()) unqualified_value_type(); - m_initialized = true ; - } - - template - void emplace_assign ( Arg&& arg ) - { - destroy(); - construct(in_place_init, boost::forward(arg)) ; - } - - void emplace_assign () - { - destroy(); - construct(in_place_init) ; - } - - template - explicit optional_base ( in_place_init_t, Arg&& arg ) - : - m_initialized(false) - { - construct(in_place_init, boost::forward(arg)); - } - - explicit optional_base ( in_place_init_t ) - : - m_initialized(false) - { - construct(in_place_init); - } - - template - explicit optional_base ( in_place_init_if_t, bool cond, Arg&& arg ) - : - m_initialized(false) - { - if ( cond ) - construct(in_place_init, boost::forward(arg)); - } - - explicit optional_base ( in_place_init_if_t, bool cond ) - : - m_initialized(false) - { - if ( cond ) - construct(in_place_init); - } - -#else - - template - void construct ( in_place_init_t, const Arg& arg ) - { - ::new (m_storage.address()) unqualified_value_type( arg ); - m_initialized = true ; - } - - template - void construct ( in_place_init_t, Arg& arg ) - { - ::new (m_storage.address()) unqualified_value_type( arg ); - m_initialized = true ; - } - - void construct ( in_place_init_t ) - { - ::new (m_storage.address()) unqualified_value_type(); - m_initialized = true ; - } - - template - void emplace_assign ( const Arg& arg ) - { - destroy(); - construct(in_place_init, arg); - } - - template - void emplace_assign ( Arg& arg ) - { - destroy(); - construct(in_place_init, arg); - } - - void emplace_assign () - { - destroy(); - construct(in_place_init); - } - - template - explicit optional_base ( in_place_init_t, const Arg& arg ) - : m_initialized(false) - { - construct(in_place_init, arg); - } - - template - explicit optional_base ( in_place_init_t, Arg& arg ) - : m_initialized(false) - { - construct(in_place_init, arg); - } - - explicit optional_base ( in_place_init_t ) - : m_initialized(false) - { - construct(in_place_init); - } - - template - explicit optional_base ( in_place_init_if_t, bool cond, const Arg& arg ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init, arg); - } - - template - explicit optional_base ( in_place_init_if_t, bool cond, Arg& arg ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init, arg); - } - - explicit optional_base ( in_place_init_if_t, bool cond ) - : m_initialized(false) - { - if ( cond ) - construct(in_place_init); - } -#endif #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Constructs in-place using the given factory template void construct ( Expr&& factory, in_place_factory_base const* ) @@ -642,42 +453,8 @@ class optional_base : public optional_tag construct(factory,tag); } -#else - // Constructs in-place using the given factory - template - void construct ( Expr const& factory, in_place_factory_base const* ) - { - boost_optional_detail::construct(factory, m_storage.address()); - m_initialized = true ; - } - - // Constructs in-place using the given typed factory - template - void construct ( Expr const& factory, typed_in_place_factory_base const* ) - { - factory.apply(m_storage.address()) ; - m_initialized = true ; - } - - template - void assign_expr_to_initialized ( Expr const& factory, in_place_factory_base const* tag ) - { - destroy(); - construct(factory,tag); - } - - // Constructs in-place using the given typed factory - template - void assign_expr_to_initialized ( Expr const& factory, typed_in_place_factory_base const* tag ) - { - destroy(); - construct(factory,tag); - } #endif -#endif - -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Constructs using any expression implicitly convertible to the single argument // of a one-argument T constructor. // Converting constructions of optional from optional uses this function with @@ -698,29 +475,6 @@ class optional_base : public optional_tag { assign_value( boost::forward(expr) ); } -#else - // Constructs using any expression implicitly convertible to the single argument - // of a one-argument T constructor. - // Converting constructions of optional from optional uses this function with - // 'Expr' being of type 'U' and relying on a converting constructor of T from U. - template - void construct ( Expr const& expr, void const* ) - { - new (m_storage.address()) unqualified_value_type(expr) ; - m_initialized = true ; - } - - // Assigns using a form any expression implicitly convertible to the single argument - // of a T's assignment operator. - // Converting assignments of optional from optional uses this function with - // 'Expr' being of type 'U' and relying on a converting assignment of T from U. - template - void assign_expr_to_initialized ( Expr const& expr, void const* ) - { - assign_value(expr); - } - -#endif #ifdef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION // BCB5.64 (and probably lower versions) workaround. @@ -735,7 +489,7 @@ class optional_base : public optional_tag // For VC<=70 compilers this workaround doesn't work because the compiler issues and error // instead of choosing the wrong overload // -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES + // Notice that 'Expr' will be optional or optional (but not optional_base<..>) template void construct ( Expr&& expr, optional_tag const* ) @@ -748,26 +502,10 @@ class optional_base : public optional_tag m_initialized = true ; } } -#else - // Notice that 'Expr' will be optional or optional (but not optional_base<..>) - template - void construct ( Expr const& expr, optional_tag const* ) - { - if ( expr.is_initialized() ) - { - // An exception can be thrown here. - // It it happens, THIS will be left uninitialized. - new (m_storage.address()) unqualified_value_type(expr.get()) ; - m_initialized = true ; - } - } -#endif #endif // defined BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION void assign_value ( argument_type val ) { get_impl() = val; } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES void assign_value ( rval_reference_type val ) { get_impl() = static_cast(val); } -#endif void destroy() { @@ -928,10 +666,8 @@ class optional typedef BOOST_DEDUCED_TYPENAME base::value_type value_type ; typedef BOOST_DEDUCED_TYPENAME base::reference_type reference_type ; typedef BOOST_DEDUCED_TYPENAME base::reference_const_type reference_const_type ; -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES typedef BOOST_DEDUCED_TYPENAME base::rval_reference_type rval_reference_type ; typedef BOOST_DEDUCED_TYPENAME base::reference_type_of_temporary_wrapper reference_type_of_temporary_wrapper ; -#endif typedef BOOST_DEDUCED_TYPENAME base::pointer_type pointer_type ; typedef BOOST_DEDUCED_TYPENAME base::pointer_const_type pointer_const_type ; typedef BOOST_DEDUCED_TYPENAME base::argument_type argument_type ; @@ -948,23 +684,19 @@ class optional // Can throw if T::T(T const&) does optional ( argument_type val ) : base(optional_detail::init_value_tag(), val) {} -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates an optional initialized with 'move(val)'. // Can throw if T::T(T &&) does optional ( rval_reference_type val ) : base(optional_detail::init_value_tag(), boost::forward(val)) {} -#endif // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T const&) does optional ( bool cond, argument_type val ) : base(cond,val) {} -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES /// Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T &&) does optional ( bool cond, rval_reference_type val ) : base( cond, boost::forward(val) ) {} -#endif // NOTE: MSVC needs templated versions first @@ -984,7 +716,6 @@ class optional this->construct(rhs.get()); } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates a deep move of another convertible optional // Requires a valid conversion from U to T. // Can throw if T::T(U&&) does @@ -1000,7 +731,6 @@ class optional if ( rhs.is_initialized() ) this->construct( boost::move(rhs.get()) ); } -#endif #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT // Creates an optional with an expression which can be either @@ -1012,7 +742,6 @@ class optional // even though explicit overloads are present for these. // Depending on the above some T ctor is called. // Can throw if the resolved T ctor throws. -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template @@ -1022,10 +751,6 @@ class optional : base(boost::forward(expr),boost::addressof(expr)) {} -#else - template - explicit optional ( Expr const& expr ) : base(expr,boost::addressof(expr)) {} -#endif // !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #endif // !defined BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT // Creates a deep copy of another optional @@ -1036,10 +761,8 @@ class optional optional ( optional const& rhs ) : base( static_cast(rhs) ) {} #endif -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates a deep move of another optional // Can throw if T::T(T&&) does - #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS optional ( optional && ) = default; #else @@ -1049,7 +772,6 @@ class optional {} #endif -#endif #if BOOST_WORKAROUND(_MSC_VER, <= 1600) // On old MSVC compilers the implicitly declared dtor is not called @@ -1060,7 +782,6 @@ class optional #if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION) // Assigns from an expression. See corresponding constructor. // Basic Guarantee: If the resolved T ctor throws, this is left UNINITIALIZED -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template BOOST_DEDUCED_TYPENAME boost::enable_if, optional&>::type @@ -1070,14 +791,6 @@ class optional return *this ; } -#else - template - optional& operator= ( Expr const& expr ) - { - this->assign_expr(expr,boost::addressof(expr)); - return *this ; - } -#endif // !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #endif // !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION) // Copy-assigns from another convertible optional (converts && deep-copies the rhs value) @@ -1090,7 +803,6 @@ class optional return *this ; } -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Move-assigns from another convertible optional (converts && deep-moves the rhs value) // Requires a valid conversion from U to T. // Basic Guarantee: If T::T( U && ) throws, this is left UNINITIALIZED @@ -1100,7 +812,6 @@ class optional this->assign(boost::move(rhs)); return *this ; } -#endif // Assigns from another optional (deep-copies the rhs value) // Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED @@ -1115,7 +826,6 @@ class optional } #endif -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Assigns from another optional (deep-moves the rhs value) #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS optional& operator= ( optional && ) = default; @@ -1128,9 +838,7 @@ class optional } #endif -#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES -#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX // Assigns from a T (deep-moves/copies the rhs value) template @@ -1141,26 +849,6 @@ class optional return *this ; } -#else - - // Assigns from a T (deep-copies the rhs value) - // Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED - optional& operator= ( argument_type val ) - { - this->assign( val ) ; - return *this ; - } - -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES - // Assigns from a T (deep-moves the rhs value) - optional& operator= ( rval_reference_type val ) - { - this->assign( boost::move(val) ) ; - return *this ; - } -#endif - -#endif // BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX // Assigns from a "none" // Which destroys the current value, if any, leaving this UNINITIALIZED @@ -1171,7 +859,6 @@ class optional return *this ; } -#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES) // Constructs in-place // upon exception *this is always uninitialized template @@ -1190,82 +877,6 @@ class optional : base( in_place_init_if, cond, boost::forward(args)... ) {} -#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) - template - void emplace ( Arg&& arg ) - { - this->emplace_assign( boost::forward(arg) ); - } - - void emplace () - { - this->emplace_assign(); - } - - template - explicit optional ( in_place_init_t, Args&& args ) - : base( in_place_init, boost::forward(args) ) - {} - - explicit optional ( in_place_init_t ) - : base( in_place_init ) - {} - - template - explicit optional ( in_place_init_if_t, bool cond, Args&& args ) - : base( in_place_init_if, cond, boost::forward(args) ) - {} - - explicit optional ( in_place_init_if_t, bool cond ) - : base( in_place_init_if, cond ) - {} -#else - template - void emplace ( const Arg& arg ) - { - this->emplace_assign( arg ); - } - - template - void emplace ( Arg& arg ) - { - this->emplace_assign( arg ); - } - - void emplace () - { - this->emplace_assign(); - } - - template - explicit optional ( in_place_init_t, const Arg& arg ) - : base( in_place_init, arg ) - {} - - template - explicit optional ( in_place_init_t, Arg& arg ) - : base( in_place_init, arg ) - {} - - explicit optional ( in_place_init_t ) - : base( in_place_init ) - {} - - template - explicit optional ( in_place_init_if_t, bool cond, const Arg& arg ) - : base( in_place_init_if, cond, arg ) - {} - - template - explicit optional ( in_place_init_if_t, bool cond, Arg& arg ) - : base( in_place_init_if, cond, arg ) - {} - - explicit optional ( in_place_init_if_t, bool cond ) - : base( in_place_init_if, cond ) - {} -#endif - void swap( optional & arg ) BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && ::boost::is_nothrow_move_assignable::value) { @@ -1293,16 +904,10 @@ class optional // Returns a reference to the value if this is initialized, otherwise, // the behaviour is UNDEFINED // No-throw -#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) reference_const_type operator *() const& { return this->get() ; } reference_type operator *() & { return this->get() ; } reference_type_of_temporary_wrapper operator *() && { return boost::move(this->get()) ; } -#else - reference_const_type operator *() const { return this->get() ; } - reference_type operator *() { return this->get() ; } -#endif // !defined BOOST_NO_CXX11_REF_QUALIFIERS -#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) reference_const_type value() const& { if (this->is_initialized()) @@ -1327,26 +932,8 @@ class optional throw_exception(bad_optional_access()); } -#else - reference_const_type value() const - { - if (this->is_initialized()) - return this->get() ; - else - throw_exception(bad_optional_access()); - } - - reference_type value() - { - if (this->is_initialized()) - return this->get() ; - else - throw_exception(bad_optional_access()); - } -#endif -#ifndef BOOST_NO_CXX11_REF_QUALIFIERS template value_type value_or ( U&& v ) const& { @@ -1364,36 +951,7 @@ class optional else return boost::forward(v); } -#elif !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES - template - value_type value_or ( U&& v ) const - { - if (this->is_initialized()) - return get(); - else - return boost::forward(v); - } -#else - template - value_type value_or ( U const& v ) const - { - if (this->is_initialized()) - return get(); - else - return v; - } - template - value_type value_or ( U& v ) const - { - if (this->is_initialized()) - return get(); - else - return v; - } -#endif - -#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) template value_type value_or_eval ( F f ) const& { @@ -1469,57 +1027,6 @@ class optional return none; } -#else - template - value_type value_or_eval ( F f ) const - { - if (this->is_initialized()) - return get(); - else - return f(); - } - - template - optional::type> - map(F f) - { - if (this->has_value()) - return f(get()); - else - return none; - } - - template - optional::type> - map(F f) const - { - if (this->has_value()) - return f(get()); - else - return none; - } - - template - optional::type> - flat_map(F f) - { - if (this->has_value()) - return f(get()); - else - return none; - } - - template - optional::type> - flat_map(F f) const - { - if (this->has_value()) - return f(get()); - else - return none; - } - -#endif bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; } @@ -1527,13 +1034,11 @@ class optional } ; -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template class optional { BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, "Optional rvalue references are illegal."); } ; -#endif } // namespace boost @@ -1543,7 +1048,6 @@ class optional namespace boost { -#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template inline @@ -1560,25 +1064,6 @@ optional::type> make_optional ( bool cond return optional::type>(cond,boost::forward(v)); } -#else - -// Returns optional(v) -template -inline -optional make_optional ( T const& v ) -{ - return optional(v); -} - -// Returns optional(cond,v) -template -inline -optional make_optional ( bool cond, T const& v ) -{ - return optional(cond,v); -} - -#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED. // No-throw