diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2022-08-08 16:36:10 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2022-08-08 16:36:10 +0300 |
commit | 79ca9f4e16c42facc3f95df7611c8abd1b7740d7 (patch) | |
tree | 4fdb4f335ac0484a26484497f8725e1e2bbfb5a7 | |
parent | 3aaac9ab67e4e37f3e9b520bee36f4b67643e29c (diff) | |
download | ydb-79ca9f4e16c42facc3f95df7611c8abd1b7740d7.tar.gz |
Update contrib/restricted/boost/optional to 1.79.0
8 files changed, 282 insertions, 131 deletions
diff --git a/contrib/restricted/boost/optional/include/boost/none.hpp b/contrib/restricted/boost/optional/include/boost/none.hpp index a37c45c5143..5f927cc36b8 100644 --- a/contrib/restricted/boost/optional/include/boost/none.hpp +++ b/contrib/restricted/boost/optional/include/boost/none.hpp @@ -13,6 +13,7 @@ #ifndef BOOST_NONE_17SEP2003_HPP #define BOOST_NONE_17SEP2003_HPP +#include "boost/config.hpp" #include "boost/none_t.hpp" // NOTE: Borland users have to include this header outside any precompiled headers @@ -23,7 +24,7 @@ namespace boost { #ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE -none_t const none = (static_cast<none_t>(0)) ; +BOOST_INLINE_VARIABLE none_t BOOST_CONSTEXPR_OR_CONST none = (static_cast<none_t>(0)) ; #elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE @@ -35,7 +36,7 @@ namespace detail { namespace optional_detail { { static const T instance; }; - + template <typename T> const T none_instance<T>::instance = T(); // global, but because 'tis a template, no cpp file required @@ -44,16 +45,15 @@ namespace detail { namespace optional_detail { namespace { // TU-local - const none_t& none = detail::optional_detail::none_instance<none_t>::instance; + const none_t& none = detail::optional_detail::none_instance<none_t>::instance; } #else -const none_t none ((none_t::init_tag())); +BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST none_t none ((none_t::init_tag())); #endif // older definitions } // namespace boost #endif // header guard - diff --git a/contrib/restricted/boost/optional/include/boost/none_t.hpp b/contrib/restricted/boost/optional/include/boost/none_t.hpp index 008f369d1cd..6b3c8334dd3 100644 --- a/contrib/restricted/boost/optional/include/boost/none_t.hpp +++ b/contrib/restricted/boost/optional/include/boost/none_t.hpp @@ -13,6 +13,8 @@ #ifndef BOOST_NONE_T_17SEP2003_HPP #define BOOST_NONE_T_17SEP2003_HPP +#include <boost/config.hpp> + namespace boost { #ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE @@ -29,7 +31,7 @@ class none_t {}; struct none_t { struct init_tag{}; - explicit none_t(init_tag){} // to disable default constructor + explicit BOOST_CONSTEXPR none_t(init_tag){} // to disable default constructor }; #endif // old implementation workarounds diff --git a/contrib/restricted/boost/optional/include/boost/optional/bad_optional_access.hpp b/contrib/restricted/boost/optional/include/boost/optional/bad_optional_access.hpp index cabf43fbace..add7867545f 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/bad_optional_access.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/bad_optional_access.hpp @@ -19,6 +19,11 @@ namespace boost { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wweak-vtables" +#endif + class bad_optional_access : public std::logic_error { public: @@ -27,6 +32,10 @@ public: {} }; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + } // namespace boost #endif diff --git a/contrib/restricted/boost/optional/include/boost/optional/detail/old_optional_implementation.hpp b/contrib/restricted/boost/optional/include/boost/optional/detail/old_optional_implementation.hpp index 62c31eecebb..3431e155a4a 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/detail/old_optional_implementation.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/detail/old_optional_implementation.hpp @@ -14,10 +14,9 @@ #define BOOST_OPTIONAL_DETAIL_OLD_OPTIONAL_IMPLEMENTATION_AJK_28JAN2015_HPP #include <boost/detail/reference_content.hpp> -#include <boost/mpl/bool.hpp> -#include <boost/mpl/if.hpp> -#include <boost/mpl/not.hpp> #include <boost/type_traits/is_reference.hpp> +#include <boost/type_traits/integral_constant.hpp> +#include <boost/type_traits/conditional.hpp> namespace boost { @@ -80,7 +79,7 @@ class optional_base : public optional_tag private : typedef -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) BOOST_DEDUCED_TYPENAME #endif ::boost::detail::make_reference_content<T>::type internal_type ; @@ -96,13 +95,13 @@ class optional_base : public optional_tag typedef T value_type ; - typedef mpl::true_ is_reference_tag ; - typedef mpl::false_ is_not_reference_tag ; + typedef true_type is_reference_tag ; + typedef false_type is_not_reference_tag ; typedef BOOST_DEDUCED_TYPENAME is_reference<T>::type is_reference_predicate ; public: - typedef BOOST_DEDUCED_TYPENAME mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ; + typedef BOOST_DEDUCED_TYPENAME conditional<is_reference_predicate::value,types_when_ref,types_when_not_ref>::type types ; protected: typedef BOOST_DEDUCED_TYPENAME types::reference_type reference_type ; @@ -333,7 +332,7 @@ class optional_base : public optional_tag public : - // **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED + // Destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) void reset() BOOST_NOEXCEPT { destroy(); } @@ -422,7 +421,7 @@ class optional_base : public optional_tag template<class Expr> void construct ( Expr&& factory, in_place_factory_base const* ) { - BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ; + BOOST_STATIC_ASSERT ( !is_reference_predicate::value ) ; boost_optional_detail::construct<value_type>(factory, m_storage.address()); m_initialized = true ; } @@ -431,7 +430,7 @@ class optional_base : public optional_tag template<class Expr> void construct ( Expr&& factory, typed_in_place_factory_base const* ) { - BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ; + BOOST_STATIC_ASSERT ( !is_reference_predicate::value ) ; factory.apply(m_storage.address()) ; m_initialized = true ; } @@ -456,7 +455,7 @@ class optional_base : public optional_tag template<class Expr> void construct ( Expr const& factory, in_place_factory_base const* ) { - BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ; + BOOST_STATIC_ASSERT ( !is_reference_predicate::value ) ; boost_optional_detail::construct<value_type>(factory, m_storage.address()); m_initialized = true ; } @@ -465,7 +464,7 @@ class optional_base : public optional_tag template<class Expr> void construct ( Expr const& factory, typed_in_place_factory_base const* ) { - BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ; + BOOST_STATIC_ASSERT ( !is_reference_predicate::value ) ; factory.apply(m_storage.address()) ; m_initialized = true ; } @@ -620,7 +619,7 @@ class optional_base : public optional_tag reference_const_type dereference( internal_type const* p, is_reference_tag ) const { return p->get() ; } reference_type dereference( internal_type* p, is_reference_tag ) { return p->get() ; } -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581)) +#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581)) void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->internal_type::~internal_type() ; m_initialized = false ; } #else void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->~T() ; m_initialized = false ; } diff --git a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_config.hpp b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_config.hpp index bb7e12f9fc1..73f25054861 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_config.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_config.hpp @@ -28,7 +28,7 @@ # define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT #endif -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551) +#if BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x551) // BCB (5.5.1) cannot parse the nested template struct in an inplace factory. # define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT #endif diff --git a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_reference_spec.hpp b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_reference_spec.hpp index 012e91a66c0..0dfeeefaf3f 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_reference_spec.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_reference_spec.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2016 Andrzej Krzemienski. +// Copyright (C) 2015-2018 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -151,7 +151,14 @@ public: T* get_ptr() const BOOST_NOEXCEPT { return ptr_; } T* operator->() const { BOOST_ASSERT(ptr_); return ptr_; } T& operator*() const { BOOST_ASSERT(ptr_); return *ptr_; } - T& value() const { return ptr_ ? *ptr_ : (throw_exception(bad_optional_access()), *ptr_); } + + T& value() const + { + if (this->is_initialized()) + return this->get(); + else + throw_exception(bad_optional_access()); + } bool operator!() const BOOST_NOEXCEPT { return ptr_ == 0; } BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() @@ -159,6 +166,25 @@ public: void reset() BOOST_NOEXCEPT { ptr_ = 0; } bool is_initialized() const BOOST_NOEXCEPT { return ptr_ != 0; } + bool has_value() const BOOST_NOEXCEPT { return ptr_ != 0; } + + template <typename F> + optional<typename boost::result_of<F(T&)>::type> map(F f) const + { + if (this->has_value()) + return f(this->get()); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(T&)>::type>::type> flat_map(F f) const + { + if (this->has_value()) + return f(get()); + else + return none; + } #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES diff --git a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_trivially_copyable_base.hpp b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_trivially_copyable_base.hpp index 91328ac4e77..2cabf9a7c6c 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/detail/optional_trivially_copyable_base.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/detail/optional_trivially_copyable_base.hpp @@ -30,7 +30,7 @@ class tc_optional_base : public optional_tag : m_initialized(false) {} - tc_optional_base ( argument_type val ) + tc_optional_base ( init_value_tag, argument_type val ) : m_initialized(true), m_storage(val) {} @@ -71,7 +71,7 @@ class tc_optional_base : public optional_tag // Assigns from another optional<T> (deep-copies the rhs value) void assign ( tc_optional_base const& rhs ) { - this->operator=(rhs); + *this = rhs; } // Assigns from another _convertible_ optional<U> (deep-copies the rhs value) @@ -127,7 +127,7 @@ class tc_optional_base : public optional_tag public : - // **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED + // Destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) void reset() BOOST_NOEXCEPT { destroy(); } @@ -359,7 +359,7 @@ class tc_optional_base : public optional_tag template<class Expr> void construct ( Expr const& factory, in_place_factory_base const* ) { - boost_optional_detail::construct<value_type>(factory, m_storage.address()); + boost_optional_detail::construct<value_type>(factory, boost::addressof(m_storage)); m_initialized = true ; } diff --git a/contrib/restricted/boost/optional/include/boost/optional/optional.hpp b/contrib/restricted/boost/optional/include/boost/optional/optional.hpp index 74ef49c5496..aadc975a7ae 100644 --- a/contrib/restricted/boost/optional/include/boost/optional/optional.hpp +++ b/contrib/restricted/boost/optional/include/boost/optional/optional.hpp @@ -1,5 +1,5 @@ // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal. -// Copyright (C) 2014 - 2017 Andrzej Krzemienski. +// Copyright (C) 2014 - 2018 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -53,25 +53,41 @@ #include <boost/move/utility.hpp> #include <boost/none.hpp> #include <boost/utility/compare_pointees.hpp> +#include <boost/utility/result_of.hpp> #include <boost/optional/optional_fwd.hpp> #include <boost/optional/detail/optional_config.hpp> #include <boost/optional/detail/optional_factory_support.hpp> #include <boost/optional/detail/optional_aligned_storage.hpp> +namespace boost { namespace optional_detail { + +template <typename T> +struct optional_value_type +{ +}; + +template <typename T> +struct optional_value_type< ::boost::optional<T> > +{ + typedef T type; +}; + +}} // namespace boost::optional_detail + #ifdef BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL #include <boost/optional/detail/old_optional_implementation.hpp> #else namespace boost { - + namespace optional_ns { - + // a tag for in-place initialization of contained value struct in_place_init_t { struct init_tag{}; explicit in_place_init_t(init_tag){} -}; +}; const in_place_init_t in_place_init ((in_place_init_t::init_tag())); // a tag for conditional in-place initialization of contained value @@ -81,7 +97,7 @@ struct in_place_init_if_t explicit in_place_init_if_t(init_tag){} }; const in_place_init_if_t in_place_init_if ((in_place_init_if_t::init_tag())); - + } // namespace optional_ns using optional_ns::in_place_init_t; @@ -91,7 +107,9 @@ using optional_ns::in_place_init_if; namespace optional_detail { -struct optional_tag {} ; +struct init_value_tag {}; + +struct optional_tag {}; template<class T> @@ -131,7 +149,7 @@ class optional_base : public optional_tag // Creates an optional<T> initialized with 'val'. // Can throw if T::T(T const&) does - optional_base ( argument_type val ) + optional_base ( init_value_tag, argument_type val ) : m_initialized(false) { @@ -141,7 +159,7 @@ class optional_base : public optional_tag #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // move-construct an optional<T> initialized from an rvalue-ref to 'val'. // Can throw if T::T(T&&) does - optional_base ( rval_reference_type val ) + optional_base ( init_value_tag, rval_reference_type val ) : m_initialized(false) { @@ -251,7 +269,7 @@ class optional_base : public optional_tag construct(rhs.get_impl()); } } - + #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Assigns from another optional<T> (deep-moves the rhs value) void assign ( optional_base&& rhs ) @@ -268,7 +286,7 @@ class optional_base : public optional_tag construct(boost::move(rhs.get_impl())); } } -#endif +#endif // Assigns from another _convertible_ optional<U> (deep-copies the rhs value) template<class U> @@ -282,7 +300,7 @@ class optional_base : public optional_tag #else assign_value( static_cast<value_type>(rhs.get()) ); #endif - + else destroy(); } else @@ -315,7 +333,7 @@ class optional_base : public optional_tag } } #endif - + // Assigns from a T (deep-copies the rhs value) void assign ( argument_type val ) { @@ -323,7 +341,7 @@ class optional_base : public optional_tag assign_value(val); 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 ) @@ -362,7 +380,7 @@ class optional_base : public optional_tag public : - // **DEPPRECATED** Destroys the current value, if any, leaving this UNINITIALIZED + // Destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) void reset() BOOST_NOEXCEPT { destroy(); } @@ -375,7 +393,7 @@ class optional_base : public optional_tag pointer_const_type get_ptr() const { return m_initialized ? get_ptr_impl() : 0 ; } pointer_type get_ptr() { return m_initialized ? get_ptr_impl() : 0 ; } - bool is_initialized() const { return m_initialized ; } + bool is_initialized() const BOOST_NOEXCEPT { return m_initialized ; } protected : @@ -384,7 +402,7 @@ class optional_base : public optional_tag ::new (m_storage.address()) value_type(val) ; m_initialized = true ; } - + #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES void construct ( rval_reference_type val ) { @@ -410,7 +428,7 @@ class optional_base : public optional_tag destroy(); construct(in_place_init, boost::forward<Args>(args)...); } - + template<class... Args> explicit optional_base ( in_place_init_t, Args&&... args ) : @@ -418,7 +436,7 @@ class optional_base : public optional_tag { construct(in_place_init, boost::forward<Args>(args)...); } - + template<class... Args> explicit optional_base ( in_place_init_if_t, bool cond, Args&&... args ) : @@ -434,26 +452,26 @@ class optional_base : public optional_tag ::new (m_storage.address()) value_type( boost::forward<Arg>(arg) ); m_initialized = true ; } - + void construct ( in_place_init_t ) { ::new (m_storage.address()) value_type(); m_initialized = true ; } - + template<class Arg> void emplace_assign ( Arg&& arg ) { destroy(); construct(in_place_init, boost::forward<Arg>(arg)) ; } - + void emplace_assign () { destroy(); construct(in_place_init) ; } - + template<class Arg> explicit optional_base ( in_place_init_t, Arg&& arg ) : @@ -461,14 +479,14 @@ class optional_base : public optional_tag { construct(in_place_init, boost::forward<Arg>(arg)); } - + explicit optional_base ( in_place_init_t ) : m_initialized(false) { construct(in_place_init); } - + template<class Arg> explicit optional_base ( in_place_init_if_t, bool cond, Arg&& arg ) : @@ -477,7 +495,7 @@ class optional_base : public optional_tag if ( cond ) construct(in_place_init, boost::forward<Arg>(arg)); } - + explicit optional_base ( in_place_init_if_t, bool cond ) : m_initialized(false) @@ -487,21 +505,21 @@ class optional_base : public optional_tag } #else - + template<class Arg> void construct ( in_place_init_t, const Arg& arg ) { ::new (m_storage.address()) value_type( arg ); m_initialized = true ; } - + template<class Arg> void construct ( in_place_init_t, Arg& arg ) { ::new (m_storage.address()) value_type( arg ); m_initialized = true ; } - + void construct ( in_place_init_t ) { ::new (m_storage.address()) value_type(); @@ -514,20 +532,20 @@ class optional_base : public optional_tag destroy(); construct(in_place_init, arg); } - + template<class Arg> void emplace_assign ( Arg& arg ) { destroy(); construct(in_place_init, arg); } - + void emplace_assign () { destroy(); construct(in_place_init); } - + template<class Arg> explicit optional_base ( in_place_init_t, const Arg& arg ) : m_initialized(false) @@ -541,13 +559,13 @@ class optional_base : public optional_tag { construct(in_place_init, arg); } - + explicit optional_base ( in_place_init_t ) : m_initialized(false) { construct(in_place_init); } - + template<class Arg> explicit optional_base ( in_place_init_if_t, bool cond, const Arg& arg ) : m_initialized(false) @@ -555,15 +573,15 @@ class optional_base : public optional_tag if ( cond ) construct(in_place_init, arg); } - + template<class Arg> 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) { @@ -757,11 +775,9 @@ class optional_base : public optional_tag storage_type m_storage ; } ; - - #include <boost/optional/detail/optional_trivially_copyable_base.hpp> -// definition of metafunciton is_optional_val_init_candidate +// definition of metafunction is_optional_val_init_candidate template <typename U> struct is_optional_related : boost::conditional< boost::is_base_of<optional_detail::optional_tag, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value @@ -772,7 +788,7 @@ struct is_optional_related {}; #if !defined(BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT) - + template <typename T, typename U> struct is_convertible_to_T_or_factory : boost::conditional< boost::is_base_of<boost::in_place_factory_base, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value @@ -797,9 +813,14 @@ struct is_optional_constructible : boost::true_type #endif // is_convertible condition -template <typename T, typename U> +template <typename T, typename U, bool = is_optional_related<U>::value> struct is_optional_val_init_candidate - : boost::conditional< !is_optional_related<U>::value && is_convertible_to_T_or_factory<T, U>::value + : boost::false_type +{}; + +template <typename T, typename U> +struct is_optional_val_init_candidate<T, U, false> + : boost::conditional< is_convertible_to_T_or_factory<T, U>::value , boost::true_type, boost::false_type>::type {}; @@ -856,12 +877,12 @@ class optional // Creates an optional<T> initialized with 'val'. // Can throw if T::T(T const&) does - optional ( argument_type val ) : base(val) {} + optional ( argument_type val ) : base(optional_detail::init_value_tag(), val) {} #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates an optional<T> initialized with 'move(val)'. // Can throw if T::T(T &&) does - optional ( rval_reference_type val ) : base( boost::forward<T>(val) ) + optional ( rval_reference_type val ) : base(optional_detail::init_value_tag(), boost::forward<T>(val)) {} #endif @@ -872,7 +893,7 @@ class optional #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES /// Creates an optional<T> 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<T>(val) ) + optional ( bool cond, rval_reference_type val ) : base( cond, boost::forward<T>(val) ) {} #endif @@ -889,11 +910,11 @@ class optional ) : base() - { + { if ( rhs.is_initialized() ) this->construct(rhs.get()); } - + #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Creates a deep move of another convertible optional<U> // Requires a valid conversion from U to T. @@ -926,10 +947,10 @@ class optional template<class Expr> - explicit optional ( Expr&& expr, - BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate<T, Expr>, bool>::type = true - ) - : base(boost::forward<Expr>(expr),boost::addressof(expr)) + explicit optional ( Expr&& expr, + BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate<T, Expr>, bool>::type = true + ) + : base(boost::forward<Expr>(expr),boost::addressof(expr)) {} #else @@ -951,7 +972,7 @@ class optional // Can throw if T::T(T&&) does #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS - optional ( optional && rhs ) = default; + optional ( optional && ) = default; #else optional ( optional && rhs ) BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value) @@ -973,7 +994,7 @@ class optional #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template<class Expr> - BOOST_DEDUCED_TYPENAME boost::enable_if<optional_detail::is_optional_val_init_candidate<T, Expr>, optional&>::type + BOOST_DEDUCED_TYPENAME boost::enable_if<optional_detail::is_optional_val_init_candidate<T, Expr>, optional&>::type operator= ( Expr&& expr ) { this->assign_expr(boost::forward<Expr>(expr),boost::addressof(expr)); @@ -999,7 +1020,7 @@ class optional this->assign(rhs); return *this ; } - + #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES // Move-assigns from another convertible optional<U> (converts && deep-moves the rhs value) // Requires a valid conversion from U to T. @@ -1030,14 +1051,14 @@ class optional #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS optional& operator= ( optional && ) = default; #else - optional& operator= ( optional && rhs ) + optional& operator= ( optional && rhs ) BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && ::boost::is_nothrow_move_assignable<T>::value) { this->assign( static_cast<base &&>(rhs) ) ; return *this ; } -#endif - +#endif + #endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX @@ -1050,7 +1071,7 @@ class optional this->assign( boost::forward<T_>(val) ) ; return *this ; } - + #else // Assigns from a T (deep-copies the rhs value) @@ -1060,7 +1081,7 @@ class optional 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 ) @@ -1069,9 +1090,9 @@ class optional return *this ; } #endif - + #endif // BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX - + // Assigns from a "none" // Which destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) @@ -1080,7 +1101,7 @@ class optional this->assign( none_ ) ; 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 @@ -1089,29 +1110,29 @@ class optional { this->emplace_assign( boost::forward<Args>(args)... ); } - + template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) : base( in_place_init, boost::forward<Args>(args)... ) {} - + template<class... Args> explicit optional ( in_place_init_if_t, bool cond, Args&&... args ) : base( in_place_init_if, cond, boost::forward<Args>(args)... ) {} - + #elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) template<class Arg> void emplace ( Arg&& arg ) { this->emplace_assign( boost::forward<Arg>(arg) ); } - + void emplace () { this->emplace_assign(); } - + template<class Args> explicit optional ( in_place_init_t, Args&& args ) : base( in_place_init, boost::forward<Args>(args) ) @@ -1120,12 +1141,12 @@ class optional explicit optional ( in_place_init_t ) : base( in_place_init ) {} - + template<class Args> explicit optional ( in_place_init_if_t, bool cond, Args&& args ) : base( in_place_init_if, cond, boost::forward<Args>(args) ) {} - + explicit optional ( in_place_init_if_t, bool cond ) : base( in_place_init_if, cond ) {} @@ -1135,23 +1156,23 @@ class optional { this->emplace_assign( arg ); } - + template<class Arg> void emplace ( Arg& arg ) { this->emplace_assign( arg ); } - + void emplace () { this->emplace_assign(); } - + template<class Arg> explicit optional ( in_place_init_t, const Arg& arg ) : base( in_place_init, arg ) {} - + template<class Arg> explicit optional ( in_place_init_t, Arg& arg ) : base( in_place_init, arg ) @@ -1160,17 +1181,17 @@ class optional explicit optional ( in_place_init_t ) : base( in_place_init ) {} - + template<class Arg> explicit optional ( in_place_init_if_t, bool cond, const Arg& arg ) : base( in_place_init_if, cond, arg ) {} - + template<class Arg> 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 ) {} @@ -1203,7 +1224,7 @@ 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) +#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()) ; } @@ -1212,42 +1233,42 @@ class optional 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) +#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) 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()); } - + reference_type_of_temporary_wrapper value() && - { + { if (this->is_initialized()) return boost::move(this->get()) ; else throw_exception(bad_optional_access()); } -#else +#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 @@ -1259,16 +1280,16 @@ class optional #ifndef BOOST_NO_CXX11_REF_QUALIFIERS template <class U> value_type value_or ( U&& v ) const& - { + { if (this->is_initialized()) return get(); else return boost::forward<U>(v); } - + template <class U> - value_type value_or ( U&& v ) && - { + value_type value_or ( U&& v ) && + { if (this->is_initialized()) return boost::move(get()); else @@ -1276,7 +1297,7 @@ class optional } #elif !defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template <class U> - value_type value_or ( U&& v ) const + value_type value_or ( U&& v ) const { if (this->is_initialized()) return get(); @@ -1285,17 +1306,17 @@ class optional } #else template <class U> - value_type value_or ( U const& v ) const - { + value_type value_or ( U const& v ) const + { if (this->is_initialized()) return get(); else return v; } - + template <class U> - value_type value_or ( U& v ) const - { + value_type value_or ( U& v ) const + { if (this->is_initialized()) return get(); else @@ -1304,7 +1325,7 @@ class optional #endif -#ifndef BOOST_NO_CXX11_REF_QUALIFIERS +#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) template <typename F> value_type value_or_eval ( F f ) const& { @@ -1313,7 +1334,7 @@ class optional else return f(); } - + template <typename F> value_type value_or_eval ( F f ) && { @@ -1322,6 +1343,61 @@ class optional else return f(); } + + template <typename F> + optional<typename boost::result_of<F(reference_type)>::type> map(F f) & + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const& + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename boost::result_of<F(reference_type_of_temporary_wrapper)>::type> map(F f) && + { + if (this->has_value()) + return f(boost::move(this->get())); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type)>::type>::type> flat_map(F f) & + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_const_type)>::type>::type> flat_map(F f) const& + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type_of_temporary_wrapper)>::type>::type> flat_map(F f) && + { + if (this->has_value()) + return f(boost::move(get())); + else + return none; + } + #else template <typename F> value_type value_or_eval ( F f ) const @@ -1331,10 +1407,49 @@ class optional else return f(); } + + template <typename F> + optional<typename boost::result_of<F(reference_type)>::type> map(F f) + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type)>::type>::type> flat_map(F f) + { + if (this->has_value()) + return f(get()); + else + return none; + } + + template <typename F> + optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_const_type)>::type>::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() ; } + bool operator!() const BOOST_NOEXCEPT { return !this->is_initialized() ; } - + BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() } ; @@ -1343,7 +1458,7 @@ class optional #endif // BOOST_OPTIONAL_CONFIG_USE_OLD_IMPLEMENTATION_OF_OPTIONAL namespace boost { - + #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES template<class T> class optional<T&&> @@ -1472,14 +1587,14 @@ get_pointer ( optional<T>& opt ) } // namespace boost namespace boost { - + // The following declaration prevents a bug where operator safe-bool is used upon streaming optional object if you forget the IO header. template<class CharType, class CharTrait> std::basic_ostream<CharType, CharTrait>& operator<<(std::basic_ostream<CharType, CharTrait>& os, optional_detail::optional_tag const&) { BOOST_STATIC_ASSERT_MSG(sizeof(CharType) == 0, "If you want to output boost::optional, include header <boost/optional/optional_io.hpp>"); - return os; + return os; } } // namespace boost |