mirror of
https://github.com/boostorg/optional.git
synced 2025-07-21 08:12:08 +02:00
Drop support for C++03
This commit is contained in:
@ -11,6 +11,11 @@
|
|||||||
|
|
||||||
[section:relnotes Release Notes]
|
[section:relnotes Release Notes]
|
||||||
|
|
||||||
|
[heading Boost Release 1.87]
|
||||||
|
|
||||||
|
* *Breaking change.* Dropped support for C++03. C++11 is now the required minimum.
|
||||||
|
|
||||||
|
|
||||||
[heading Boost Release 1.85]
|
[heading Boost Release 1.85]
|
||||||
|
|
||||||
* Fixed the implementation for trivial types. Now it is slower, because it always initializes the `T`, but it avoids undefined behavior when `optional<T>` is copied. This fixes [@https://github.com/boostorg/optional/issues/108 issue #108].
|
* Fixed the implementation for trivial types. Now it is slower, because it always initializes the `T`, but it avoids undefined behavior when `optional<T>` is copied. This fixes [@https://github.com/boostorg/optional/issues/108 issue #108].
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||||
// Copyright (C) 2014, 2015 Andrzej Krzemienski.
|
// Copyright (C) 2014, 2024 Andrzej Krzemienski.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -14,12 +14,11 @@
|
|||||||
#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_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)
|
|| 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)
|
||||||
|
|
||||||
BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Optional 1.83 and will be removed in Boost.Optional 1.86.")
|
#error "Boost.Optional requires C++11 or later. If you have an older C++ version use Boost.Optional version 1.86 or earlier."
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2015-2018 Andrzej Krzemienski.
|
// Copyright (C) 2015-2024 Andrzej Krzemienski.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -29,15 +29,15 @@ template <class From>
|
|||||||
void prevent_binding_rvalue()
|
void prevent_binding_rvalue()
|
||||||
{
|
{
|
||||||
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
||||||
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<From>::value,
|
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<From>::value,
|
||||||
"binding rvalue references to optional lvalue references is disallowed");
|
"binding rvalue references to optional lvalue references is disallowed");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type& forward_reference(T&& r)
|
BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type& forward_reference(T&& r)
|
||||||
{
|
{
|
||||||
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<T>::value,
|
BOOST_STATIC_ASSERT_MSG(boost::is_lvalue_reference<T>::value,
|
||||||
"binding rvalue references to optional lvalue references is disallowed");
|
"binding rvalue references to optional lvalue references is disallowed");
|
||||||
return boost::forward<T>(r);
|
return boost::forward<T>(r);
|
||||||
}
|
}
|
||||||
@ -68,10 +68,10 @@ void prevent_assignment_from_false_const_integral()
|
|||||||
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
|
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
|
||||||
// MSVC compiler without rvalue references: we need to disable the assignment from
|
// MSVC compiler without rvalue references: we need to disable the assignment from
|
||||||
// const integral lvalue reference, as it may be an invalid temporary
|
// const integral lvalue reference, as it may be an invalid temporary
|
||||||
BOOST_STATIC_ASSERT_MSG(!is_const_integral<From>::value,
|
BOOST_STATIC_ASSERT_MSG(!is_const_integral<From>::value,
|
||||||
"binding const lvalue references to integral types is disabled in this compiler");
|
"binding const lvalue references to integral types is disabled in this compiler");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ template <class T>
|
|||||||
class optional<T&> : public optional_detail::optional_tag
|
class optional<T&> : public optional_detail::optional_tag
|
||||||
{
|
{
|
||||||
T* ptr_;
|
T* ptr_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef T& value_type;
|
typedef T& value_type;
|
||||||
typedef T& reference_type;
|
typedef T& reference_type;
|
||||||
@ -122,19 +122,19 @@ public:
|
|||||||
typedef T& rval_reference_type;
|
typedef T& rval_reference_type;
|
||||||
typedef T* pointer_type;
|
typedef T* pointer_type;
|
||||||
typedef T* pointer_const_type;
|
typedef T* pointer_const_type;
|
||||||
|
|
||||||
optional() BOOST_NOEXCEPT : ptr_() {}
|
optional() BOOST_NOEXCEPT : ptr_() {}
|
||||||
optional(none_t) BOOST_NOEXCEPT : ptr_() {}
|
optional(none_t) BOOST_NOEXCEPT : ptr_() {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||||
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||||
|
|
||||||
// the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with screwed conversion construction from const int
|
// the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with screwed conversion construction from const int
|
||||||
template <class U>
|
template <class U>
|
||||||
explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(rhs)) {}
|
: ptr_(boost::addressof(rhs)) {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(rhs)) {}
|
: ptr_(boost::addressof(rhs)) {}
|
||||||
@ -143,15 +143,15 @@ public:
|
|||||||
template <class U>
|
template <class U>
|
||||||
optional& operator=(const optional<U&>& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
optional& operator=(const optional<U&>& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
||||||
optional& operator=(none_t) BOOST_NOEXCEPT { ptr_ = 0; return *this; }
|
optional& operator=(none_t) BOOST_NOEXCEPT { ptr_ = 0; return *this; }
|
||||||
|
|
||||||
|
|
||||||
void swap(optional& rhs) BOOST_NOEXCEPT { std::swap(ptr_, rhs.ptr_); }
|
void swap(optional& rhs) BOOST_NOEXCEPT { std::swap(ptr_, rhs.ptr_); }
|
||||||
T& get() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
T& get() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
||||||
|
|
||||||
T* get_ptr() const BOOST_NOEXCEPT { return ptr_; }
|
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& operator*() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
T& operator*() const { BOOST_ASSERT(ptr_); return *ptr_; }
|
||||||
|
|
||||||
T& value() const
|
T& value() const
|
||||||
{
|
{
|
||||||
if (this->is_initialized())
|
if (this->is_initialized())
|
||||||
@ -159,17 +159,17 @@ public:
|
|||||||
else
|
else
|
||||||
throw_exception(bad_optional_access());
|
throw_exception(bad_optional_access());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!() const BOOST_NOEXCEPT { return ptr_ == 0; }
|
bool operator!() const BOOST_NOEXCEPT { return ptr_ == 0; }
|
||||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||||
|
|
||||||
void reset() BOOST_NOEXCEPT { ptr_ = 0; }
|
void reset() BOOST_NOEXCEPT { ptr_ = 0; }
|
||||||
|
|
||||||
bool is_initialized() const BOOST_NOEXCEPT { return ptr_ != 0; }
|
bool is_initialized() const BOOST_NOEXCEPT { return ptr_ != 0; }
|
||||||
bool has_value() const BOOST_NOEXCEPT { return ptr_ != 0; }
|
bool has_value() const BOOST_NOEXCEPT { return ptr_ != 0; }
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(T&)>::type> map(F f) const
|
auto map(F f) const -> optional<decltype(f(**this))>
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(this->get());
|
return f(this->get());
|
||||||
@ -178,61 +178,62 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(T&)>::type>::type> flat_map(F f) const
|
auto flat_map(F f) const ->
|
||||||
|
optional<typename optional_detail::optional_value_type<decltype(f(**this))>::type>
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
else
|
else
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
|
||||||
optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::no_unboxing_cond<T, R>, bool>::type = true) BOOST_NOEXCEPT
|
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::no_unboxing_cond<T, R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue<R>(); }
|
: ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue<R>(); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, optional<T&>&>::type
|
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, optional<T&>&>::type
|
||||||
operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); return *this; }
|
operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); return *this; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
{ detail::prevent_binding_rvalue<R>(); return ptr_ ? *ptr_ : r; }
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
{ detail::prevent_binding_rvalue<R>(); ptr_ = boost::addressof(r); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
T& value_or_eval(F f) const { return ptr_ ? *ptr_ : detail::forward_reference(f()); }
|
T& value_or_eval(F f) const { return ptr_ ? *ptr_ : detail::forward_reference(f()); }
|
||||||
|
|
||||||
#else // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#else // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
|
|
||||||
|
|
||||||
// the following two implement a 'conditionally explicit' constructor
|
// the following two implement a 'conditionally explicit' constructor
|
||||||
template <class U>
|
template <class U>
|
||||||
explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(v)) { }
|
: ptr_(boost::addressof(v)) { }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value, bool>::type = true) BOOST_NOEXCEPT
|
||||||
: ptr_(boost::addressof(v)) { }
|
: ptr_(boost::addressof(v)) { }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
||||||
|
|
||||||
@ -247,26 +248,26 @@ public:
|
|||||||
template <class U>
|
template <class U>
|
||||||
void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ ptr_ = boost::addressof(v); }
|
{ ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ return ptr_ ? *ptr_ : v; }
|
{ return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) const BOOST_NOEXCEPT
|
||||||
{ return ptr_ ? *ptr_ : v; }
|
{ return ptr_ ? *ptr_ : v; }
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, bool>::type = true) BOOST_NOEXCEPT
|
||||||
{ ptr_ = boost::addressof(v); }
|
{ ptr_ = boost::addressof(v); }
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
T& value_or_eval(F f) const { return ptr_ ? *ptr_ : f(); }
|
T& value_or_eval(F f) const { return ptr_ ? *ptr_ : f(); }
|
||||||
|
|
||||||
#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void swap ( optional<T&>& x, optional<T&>& y) BOOST_NOEXCEPT
|
void swap ( optional<T&>& x, optional<T&>& y) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
x.swap(y);
|
x.swap(y);
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
#include <boost/move/utility.hpp>
|
#include <boost/move/utility.hpp>
|
||||||
#include <boost/none.hpp>
|
#include <boost/none.hpp>
|
||||||
#include <boost/utility/compare_pointees.hpp>
|
#include <boost/utility/compare_pointees.hpp>
|
||||||
#include <boost/utility/result_of.hpp>
|
|
||||||
|
|
||||||
#include <boost/optional/optional_fwd.hpp>
|
#include <boost/optional/optional_fwd.hpp>
|
||||||
#include <boost/optional/detail/optional_config.hpp>
|
#include <boost/optional/detail/optional_config.hpp>
|
||||||
@ -75,12 +74,15 @@ struct optional_value_type
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename U>
|
||||||
struct optional_value_type< ::boost::optional<T> >
|
struct optional_value_type< ::boost::optional<U> >
|
||||||
{
|
{
|
||||||
typedef T type;
|
typedef U type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T declval();
|
||||||
|
|
||||||
}} // namespace boost::optional_detail
|
}} // namespace boost::optional_detail
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
@ -1381,7 +1383,6 @@ class optional
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#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)
|
||||||
template <typename F>
|
template <typename F>
|
||||||
value_type value_or_eval ( F f ) const&
|
value_type value_or_eval ( F f ) const&
|
||||||
@ -1402,7 +1403,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(reference_type)>::type> map(F f) &
|
optional<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type>()))> map(F f) &
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1411,7 +1412,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const&
|
optional<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_const_type>()))> map(F f) const&
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1420,7 +1421,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(reference_type_of_temporary_wrapper)>::type> map(F f) &&
|
optional<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type_of_temporary_wrapper>()))> map(F f) &&
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(boost::move(this->get()));
|
return f(boost::move(this->get()));
|
||||||
@ -1429,7 +1430,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type)>::type>::type> flat_map(F f) &
|
optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type>()))>::type> flat_map(F f) &
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1438,7 +1439,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
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&
|
optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_const_type>()))>::type>flat_map(F f) const&
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1447,7 +1448,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
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) &&
|
optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type_of_temporary_wrapper>()))>::type>flat_map(F f) &&
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(boost::move(get()));
|
return f(boost::move(get()));
|
||||||
@ -1466,7 +1467,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(reference_type)>::type> map(F f)
|
optional<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type>()))> map(F f)
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1475,7 +1476,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const
|
optional<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_const_type>()))> map(F f) const
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1484,7 +1485,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
optional<typename optional_detail::optional_value_type<typename boost::result_of<F(reference_type)>::type>::type> flat_map(F f)
|
optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type>()))>::type> flat_map(F f)
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1493,7 +1494,7 @@ class optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
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
|
optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_const_type>()))>::type> flat_map(F f) const
|
||||||
{
|
{
|
||||||
if (this->has_value())
|
if (this->has_value())
|
||||||
return f(get());
|
return f(get());
|
||||||
@ -1505,9 +1506,7 @@ class optional
|
|||||||
|
|
||||||
bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }
|
bool has_value() const BOOST_NOEXCEPT { return this->is_initialized() ; }
|
||||||
|
|
||||||
bool operator!() const BOOST_NOEXCEPT { return !this->is_initialized() ; }
|
explicit operator bool() const BOOST_NOEXCEPT { return this->has_value() ; }
|
||||||
|
|
||||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,13 +29,15 @@ void test()
|
|||||||
{
|
{
|
||||||
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
boost::optional<int> v = Wrapper();
|
boost::optional<int> v = Wrapper();
|
||||||
BOOST_TEST(v);
|
//BOOST_TEST(v);
|
||||||
|
boost::optional<boost::optional<int>> vv;
|
||||||
|
bool xx = vv?true : false;
|
||||||
BOOST_TEST_EQ(*v, 7);
|
BOOST_TEST_EQ(*v, 7);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test();
|
test();
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user