Sync from upstream.

This commit is contained in:
Rene Rivera
2024-08-17 09:11:50 -05:00
18 changed files with 284 additions and 250 deletions

View File

@ -10,6 +10,7 @@ on:
env: env:
UBSAN_OPTIONS: print_stacktrace=1 UBSAN_OPTIONS: print_stacktrace=1
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
jobs: jobs:
posix: posix:
@ -58,7 +59,7 @@ jobs:
address-model: 32,64 address-model: 32,64
- toolset: gcc-11 - toolset: gcc-11
cxxstd: "03,11,14,17,20" cxxstd: "03,11,14,17,20"
os: ubuntu-20.04 os: ubuntu-22.04
install: g++-11-multilib install: g++-11-multilib
address-model: 32,64 address-model: 32,64
- toolset: gcc-12 - toolset: gcc-12

View File

@ -18,12 +18,11 @@ target_link_libraries(boost_optional
Boost::config Boost::config
Boost::core Boost::core
Boost::move Boost::move
Boost::predef
Boost::static_assert Boost::static_assert
Boost::throw_exception Boost::throw_exception
Boost::type_traits Boost::type_traits
Boost::utility
) )
target_compile_features(boost_optional INTERFACE cxx_std_11)
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

View File

@ -18,11 +18,9 @@ The implementation uses the following other Boost modules:
# config # config
# core # core
# move # move
# mpl
# static_assert # static_assert
# throw_exception # throw_exception
# type_traits # type_traits
# utility
[endsect] [endsect]

View File

@ -11,6 +11,14 @@
[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.
* Dropped dependency on Boost.Utility.
* Dropped dependency on Boost.Predef.
* A bit faster implementation of some relational operations.
[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].

View File

@ -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

View File

@ -12,9 +12,6 @@
#ifndef BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP #ifndef BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP
#define BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP #define BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <boost/predef.h>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
// The condition to use POD implementation // The condition to use POD implementation
@ -23,8 +20,6 @@
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif defined BOOST_OPTIONAL_CONFIG_NO_SPEC_FOR_TRIVIAL_TYPES #elif defined BOOST_OPTIONAL_CONFIG_NO_SPEC_FOR_TRIVIAL_TYPES
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif !defined BOOST_HAS_TRIVIAL_CONSTRUCTOR
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif !defined BOOST_HAS_TRIVIAL_MOVE_ASSIGN #elif !defined BOOST_HAS_TRIVIAL_MOVE_ASSIGN
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif !defined BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR #elif !defined BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR
@ -35,29 +30,6 @@
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif !defined BOOST_HAS_TRIVIAL_DESTRUCTOR #elif !defined BOOST_HAS_TRIVIAL_DESTRUCTOR
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
# define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
#endif
// GCC 5 or higher, or clang with libc++ or clang with libstdc++ 5 or higher
#if __cplusplus >= 201103L
# if BOOST_WORKAROUND(BOOST_GCC, >= 50000)
# define BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
# elif (defined BOOST_CLANG)
# if BOOST_LIB_STD_CXX > 0
# define BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
# elif BOOST_LIB_STD_GNU >= 441200023 && BOOST_LIB_STD_GNU != 450600023 && BOOST_LIB_STD_GNU != 450600026 && BOOST_LIB_STD_GNU != 460800003 && BOOST_LIB_STD_GNU != 450400026 && BOOST_LIB_STD_GNU != 460700026
# define BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
# endif
# endif
#endif
#ifndef BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
# define BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T) BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)
#else
# include <type_traits>
# define BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T) std::is_trivially_default_constructible<T>::value
#endif #endif
@ -65,7 +37,7 @@ namespace boost { namespace optional_detail {
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
template <typename T> template <typename T>
struct is_type_trivially_copyable struct is_trivially_semiregular
: boost::conditional<(boost::has_trivial_copy_constructor<T>::value && : boost::conditional<(boost::has_trivial_copy_constructor<T>::value &&
boost::has_trivial_move_constructor<T>::value && boost::has_trivial_move_constructor<T>::value &&
boost::has_trivial_destructor<T>::value && boost::has_trivial_destructor<T>::value &&
@ -75,30 +47,13 @@ struct is_type_trivially_copyable
{}; {};
#else #else
template <typename T> template <typename T>
struct is_type_trivially_copyable struct is_trivially_semiregular
: boost::conditional<(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value), : boost::conditional<(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value),
boost::true_type, boost::false_type>::type boost::true_type, boost::false_type>::type
{}; {};
#endif #endif
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
template <typename T>
struct optional_uses_direct_storage_for_
: boost::conditional< (is_type_trivially_copyable<T>::value && BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T)) ||
(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value)
, boost::true_type, boost::false_type>::type
{};
#else
template <typename T>
struct optional_uses_direct_storage_for_
: boost::conditional<(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value)
, boost::true_type, boost::false_type>::type
{};
#endif
}} // boost::optional_detail }} // boost::optional_detail
#endif #endif

View File

@ -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; } explicit operator bool() const BOOST_NOEXCEPT { return ptr_ != 0; }
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 optional<typename optional_detail::result_of<F, reference_const_type>::type>
map(F f) const
{ {
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 optional<typename optional_detail::result_value_type<F, reference_const_type>::type>
flat_map(F f) const
{ {
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);

View File

@ -1,5 +1,5 @@
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal. // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
// Copyright (C) 2015 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
@ -16,7 +16,8 @@
namespace boost { namespace boost {
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values). // optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointees() in generic code instead. // WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointees() in generic code instead,
// to obtain the same semantic for pointers.
// //
@ -31,7 +32,7 @@ bool operator == ( optional<T> const& x, optional<T> const& y )
template<class T> template<class T>
inline inline
bool operator < ( optional<T> const& x, optional<T> const& y ) bool operator < ( optional<T> const& x, optional<T> const& y )
{ return less_pointees(x,y); } { return !y ? false : (!x ? true : (*x) < (*y)); }
template<class T> template<class T>
inline inline
@ -60,12 +61,12 @@ bool operator >= ( optional<T> const& x, optional<T> const& y )
template<class T> template<class T>
inline inline
bool operator == ( optional<T> const& x, T const& y ) bool operator == ( optional<T> const& x, T const& y )
{ return equal_pointees(x, optional<T>(y)); } { return x && (*x == y); }
template<class T> template<class T>
inline inline
bool operator < ( optional<T> const& x, T const& y ) bool operator < ( optional<T> const& x, T const& y )
{ return less_pointees(x, optional<T>(y)); } { return (!x) || (*x < y); }
template<class T> template<class T>
inline inline
@ -94,12 +95,12 @@ bool operator >= ( optional<T> const& x, T const& y )
template<class T> template<class T>
inline inline
bool operator == ( T const& x, optional<T> const& y ) bool operator == ( T const& x, optional<T> const& y )
{ return equal_pointees( optional<T>(x), y ); } { return y && (x == *y); }
template<class T> template<class T>
inline inline
bool operator < ( T const& x, optional<T> const& y ) bool operator < ( T const& x, optional<T> const& y )
{ return less_pointees( optional<T>(x), y ); } { return y && (x < *y); }
template<class T> template<class T>
inline inline
@ -133,8 +134,8 @@ bool operator == ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
template<class T> template<class T>
inline inline
bool operator < ( optional<T> const& x, none_t ) bool operator < ( optional<T> const&, none_t )
{ return less_pointees(x,optional<T>() ); } { return false; }
template<class T> template<class T>
inline inline
@ -168,7 +169,7 @@ bool operator == ( none_t , optional<T> const& y ) BOOST_NOEXCEPT
template<class T> template<class T>
inline inline
bool operator < ( none_t , optional<T> const& y ) bool operator < ( none_t , optional<T> const& y )
{ return less_pointees(optional<T>() ,y); } { return bool(y); }
template<class T> template<class T>
inline inline
@ -193,4 +194,3 @@ bool operator >= ( none_t x, optional<T> const& y )
} // namespace boost } // namespace boost
#endif // header guard #endif // header guard

View File

@ -22,20 +22,14 @@
#include <iosfwd> #include <iosfwd>
#endif // BOOST_NO_IOSTREAM #endif // BOOST_NO_IOSTREAM
#ifdef BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
# include <type_traits>
#endif
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/core/addressof.hpp> #include <boost/core/addressof.hpp>
#include <boost/core/enable_if.hpp> #include <boost/core/enable_if.hpp>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/core/invoke_swap.hpp> #include <boost/core/invoke_swap.hpp>
#include <boost/core/launder.hpp> #include <boost/core/launder.hpp>
#include <boost/optional/bad_optional_access.hpp> #include <boost/optional/bad_optional_access.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/alignment_of.hpp> #include <boost/type_traits/alignment_of.hpp>
#include <boost/type_traits/conditional.hpp> #include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/conjunction.hpp> #include <boost/type_traits/conjunction.hpp>
@ -59,8 +53,6 @@
#include <boost/type_traits/is_scalar.hpp> #include <boost/type_traits/is_scalar.hpp>
#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/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 +67,32 @@ 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();
// implementing my own result_of so that it works for C++11 (std::result_of)
// and in C++20 (std::invoke_result).
template <typename F, typename Ref, typename Rslt = decltype(declval<F>()(declval<Ref>()))>
struct result_of
{
typedef Rslt type;
};
template <typename F, typename Ref, typename Rslt = typename optional_value_type<typename result_of<F, Ref>::type>::type>
struct result_value_type
{
typedef Rslt type;
};
// optional<typename optional_detail::optional_value_type<decltype(optional_detail::declval<F>()(optional_detail::declval<reference_type>()))>::type>
}} // namespace boost::optional_detail }} // namespace boost::optional_detail
namespace boost { namespace boost {
@ -1381,7 +1393,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 +1413,7 @@ class optional
} }
template <typename F> template <typename F>
optional<typename boost::result_of<F(reference_type)>::type> map(F f) & optional<typename optional_detail::result_of<F, reference_type>::type> map(F f) &
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1411,7 +1422,7 @@ class optional
} }
template <typename F> template <typename F>
optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const& optional<typename optional_detail::result_of<F, reference_const_type>::type> map(F f) const&
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1420,7 +1431,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<typename optional_detail::result_of<F, reference_type_of_temporary_wrapper>::type> 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 +1440,8 @@ 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::result_value_type<F, reference_type>::type>
flat_map(F f) &
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1438,7 +1450,8 @@ 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::result_value_type<F, 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 +1460,8 @@ 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::result_value_type<F, 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 +1480,8 @@ class optional
} }
template <typename F> template <typename F>
optional<typename boost::result_of<F(reference_type)>::type> map(F f) optional<typename optional_detail::result_of<F, reference_type>::type>
map(F f)
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1475,7 +1490,8 @@ class optional
} }
template <typename F> template <typename F>
optional<typename boost::result_of<F(reference_const_type)>::type> map(F f) const optional<typename optional_detail::result_of<F, reference_const_type>::type>
map(F f) const
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1484,7 +1500,8 @@ 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::result_value_type<F, reference_type>::type>
flat_map(F f)
{ {
if (this->has_value()) if (this->has_value())
return f(get()); return f(get());
@ -1493,7 +1510,8 @@ 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::result_value_type<F, 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 +1523,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()
} ; } ;

View File

@ -13,5 +13,5 @@
"Fernando Cacciola <fernando_cacciola -at- ciudad.com.ar>", "Fernando Cacciola <fernando_cacciola -at- ciudad.com.ar>",
"Andrzej Krzemienski <akrzemi1 -at- gmail.com>" "Andrzej Krzemienski <akrzemi1 -at- gmail.com>"
], ],
"cxxstd": "03" "cxxstd": "11"
} }

View File

@ -2,6 +2,7 @@
# #
# Copyright (C) 2003, Fernando Luis Cacciola Carballal. # Copyright (C) 2003, Fernando Luis Cacciola Carballal.
# Copyright (C) 2014 - 2017 Andrzej Krzemienski # Copyright (C) 2014 - 2017 Andrzej Krzemienski
# Copyright (C) 2024 Alexander Grund
# #
# 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
@ -13,9 +14,24 @@
# akrzemi1@gmail.com # akrzemi1@gmail.com
# #
import config : requires ;
import testing ; import testing ;
project : requirements <library>/boost/optional//boost_optional ; project
: requirements
<library>/boost/optional//boost_optional
[ requires
cxx11_decltype
cxx11_defaulted_functions
cxx11_defaulted_moves
cxx11_deleted_functions
cxx11_explicit_conversion_operators
cxx11_noexcept
cxx11_rvalue_references
cxx11_variadic_templates
]
;
run optional_test.cpp : : : <library>/boost/bind//boost_bind <library>/boost/mpl//boost_mpl ; run optional_test.cpp : : : <library>/boost/bind//boost_bind <library>/boost/mpl//boost_mpl ;
run optional_test_assign.cpp ; run optional_test_assign.cpp ;
@ -44,7 +60,7 @@ run optional_test_inplace_factory.cpp ;
run optional_test_io.cpp ; run optional_test_io.cpp ;
run optional_test_move.cpp ; run optional_test_move.cpp ;
run optional_test_noexcept_move.cpp ; run optional_test_noexcept_move.cpp ;
run optional_test_equals_none.cpp ; run optional_test_cmp_none.cpp ;
run optional_test_value_access.cpp ; run optional_test_value_access.cpp ;
run optional_test_emplace.cpp ; run optional_test_emplace.cpp ;
run optional_test_minimum_requirements.cpp ; run optional_test_minimum_requirements.cpp ;

View File

@ -0,0 +1,83 @@
// Copyright (C) 2014 Andrzej Krzemienski.
// Copyright (C) 2024 Alexander Grund
//
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/lib/optional for documentation.
//
// You are welcome to contact the author at:
// akrzemi1@gmail.com
#include "boost/optional/optional.hpp"
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
#include "boost/core/lightweight_test.hpp"
#include "boost/none.hpp"
struct SemiRegular // no operator==
{
private: void operator==(SemiRegular const&) const {}
private: void operator!=(SemiRegular const&) const {}
};
void test_equal_to_none_of_noncomparable_T()
{
boost::optional<SemiRegular> i = SemiRegular();
boost::optional<SemiRegular> o;
BOOST_TEST(i != boost::none);
BOOST_TEST(boost::none != i);
BOOST_TEST(o == boost::none);
BOOST_TEST(boost::none == o);
}
void test_comparison_to_none()
{
using boost::none;
boost::optional<SemiRegular> i = SemiRegular();
// the default ordering of optional<size_t> is{ boost::none, 0, 1, 2, ... }
// Hence boost::none < i for any engaged i
// and all others operators ( ==, !=, <, <=, >, >= ) follow
BOOST_TEST(!(i == none));
BOOST_TEST(i != none);
BOOST_TEST(!(i < none));
BOOST_TEST(!(i <= none));
BOOST_TEST(i > none);
BOOST_TEST(i >= none);
// Comparison is symmetric
BOOST_TEST(!(none == i));
BOOST_TEST(none != i);
BOOST_TEST(none < i);
BOOST_TEST(none <= i);
BOOST_TEST(!(none > i));
BOOST_TEST(!(none >= i));
// An un-engaged optional is always equal to none
boost::optional<SemiRegular> o;
BOOST_TEST(o == none);
BOOST_TEST(!(o != none));
BOOST_TEST(!(o < none));
BOOST_TEST(o <= none);
BOOST_TEST(!(o > none));
BOOST_TEST(o >= none);
// Comparison is symmetric
BOOST_TEST(none == o);
BOOST_TEST(!(none != o));
BOOST_TEST(!(none < o));
BOOST_TEST(none <= o);
BOOST_TEST(!(none > o));
BOOST_TEST(none >= o);
}
int main()
{
test_equal_to_none_of_noncomparable_T();
return boost::report_errors();
}

View File

@ -25,8 +25,7 @@ struct implicit_bool_conv
struct explicit_bool_conv struct explicit_bool_conv
{ {
bool operator!() const BOOST_NOEXCEPT { return false; } explicit operator bool() const BOOST_NOEXCEPT { return true; }
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
}; };
template <typename To, typename From> template <typename To, typename From>

View File

@ -1,43 +0,0 @@
// Copyright (C) 2014 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
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/lib/optional for documentation.
//
// You are welcome to contact the author at:
// akrzemi1@gmail.com
#include "boost/optional/optional.hpp"
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
#include "boost/core/lightweight_test.hpp"
#include "boost/none.hpp"
struct SemiRegular // no operator==
{
private: void operator==(SemiRegular const&) const {}
private: void operator!=(SemiRegular const&) const {}
};
void test_equal_to_none_of_noncomparable_T()
{
boost::optional<SemiRegular> i = SemiRegular();
boost::optional<SemiRegular> o;
BOOST_TEST(i != boost::none);
BOOST_TEST(boost::none != i);
BOOST_TEST(o == boost::none);
BOOST_TEST(boost::none == o);
}
int main()
{
test_equal_to_none_of_noncomparable_T();
return boost::report_errors();
}

View File

@ -43,9 +43,9 @@ struct DeletedDefault
}; };
namespace boost { namespace optional_config { namespace boost { namespace optional_config {
template <> struct optional_uses_direct_storage_for<CustomizedTrivial> : boost::true_type {}; template <> struct optional_uses_direct_storage_for<CustomizedTrivial> : boost::true_type {};
}} }}
struct CustDtor struct CustDtor
@ -78,47 +78,47 @@ void test_type_traits()
// this only tests if type traits are implemented correctly // this only tests if type traits are implemented correctly
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<int> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<int> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<double> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<double> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<CustomizedTrivial> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<CustomizedTrivial> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<PrivDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<PrivDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<NoDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<NoDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustDefault> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDtor> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDtor> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustAssign> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustAssign> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustMove> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustMove> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustMove> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustMove> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<int> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<double> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<int> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<double> ));
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Empty> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Empty> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<Aggregate<Empty, int>, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<Aggregate<Empty, int>, double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Empty> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Empty> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<Aggregate<Empty, int>, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<Aggregate<Empty, int>, double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<PrivDefault> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<PrivDefault> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<NoDefault> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<NoDefault> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<CustDefault> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<CustDefault> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, CustDefault> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, CustDefault> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<DeletedDefault> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<DeletedDefault> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, DeletedDefault> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, DeletedDefault> > ));
#endif #endif
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<DeletedDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<DeletedDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, DeletedDefault> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustDtor> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustDtor> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustAssign> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustAssign> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustMove> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustMove> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, CustMove> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, CustMove> > ));
} }
void test_trivial_copyability() void test_trivial_copyability()
@ -127,16 +127,16 @@ void test_trivial_copyability()
BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<double>, boost::optional<double> > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<double>, boost::optional<double> > ));
BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<CustomizedTrivial>, boost::optional<CustomizedTrivial> > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<CustomizedTrivial>, boost::optional<CustomizedTrivial> > ));
BOOST_TEST_TRAIT_FALSE((boost::is_base_of<boost::optional_detail::tc_optional_base<DeletedDefault>, boost::optional<DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE((boost::is_base_of<boost::optional_detail::tc_optional_base<DeletedDefault>, boost::optional<DeletedDefault> > ));
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<int> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<int> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<CustomizedTrivial> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<CustomizedTrivial> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Empty> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Empty> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Aggregate<int, double> > > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Aggregate<int, double> > > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Aggregate<Aggregate<Empty, int>, double> > > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Aggregate<Aggregate<Empty, int>, double> > > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<boost::optional<DeletedDefault> > ));
#endif #endif
} }

View File

@ -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();
} }

View File

@ -43,9 +43,9 @@ struct DeletedDefault
}; };
namespace boost { namespace optional_config { namespace boost { namespace optional_config {
template <> struct optional_uses_direct_storage_for<CustomizedTrivial> : boost::true_type {}; template <> struct optional_uses_direct_storage_for<CustomizedTrivial> : boost::true_type {};
}} }}
struct CustDtor struct CustDtor
@ -78,40 +78,40 @@ void test_type_traits()
// this only tests if type traits are implemented correctly // this only tests if type traits are implemented correctly
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<int> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<int> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<double> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<double> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<CustomizedTrivial> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for<CustomizedTrivial> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<PrivDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<PrivDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<NoDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<NoDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustDefault> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDtor> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustDtor> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustAssign> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustAssign> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustMove> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<CustMove> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustMove> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, CustMove> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<int> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<int> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<double> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<double> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Empty> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Empty> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, double> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, double> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<Aggregate<Empty, int>, double> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<Aggregate<Empty, int>, double> > ));
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Empty> )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Empty> ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<Aggregate<Empty, int>, double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<Aggregate<Aggregate<Empty, int>, double> > ));
#endif #endif
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<DeletedDefault> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<DeletedDefault> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for<Aggregate<int, DeletedDefault> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustDtor> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustDtor> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustAssign> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustAssign> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<CustMove> )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<CustMove> ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<Aggregate<int, CustMove> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<Aggregate<int, CustMove> > ));
} }
void test_trivial_copyability() void test_trivial_copyability()
@ -120,18 +120,18 @@ void test_trivial_copyability()
BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<double>, boost::optional<double> > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<double>, boost::optional<double> > ));
BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<CustomizedTrivial>, boost::optional<CustomizedTrivial> > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of<boost::optional_detail::tc_optional_base<CustomizedTrivial>, boost::optional<CustomizedTrivial> > ));
BOOST_TEST_TRAIT_FALSE((boost::is_base_of<boost::optional_detail::tc_optional_base<DeletedDefault>, boost::optional<DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE((boost::is_base_of<boost::optional_detail::tc_optional_base<DeletedDefault>, boost::optional<DeletedDefault> > ));
#ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<int> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<int> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<double> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<double> > ));
BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<CustomizedTrivial> > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_trivially_semiregular<boost::optional<CustomizedTrivial> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<DeletedDefault> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<boost::optional<DeletedDefault> > ));
#endif #endif
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Empty> > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Empty> > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Aggregate<int, double> > > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Aggregate<int, double> > > ));
BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable<boost::optional<Aggregate<Aggregate<Empty, int>, double> > > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_trivially_semiregular<boost::optional<Aggregate<Aggregate<Empty, int>, double> > > ));
} }
#endif #endif

View File

@ -11,7 +11,7 @@
#include "boost/core/lightweight_test.hpp" #include "boost/core/lightweight_test.hpp"
#include "boost/optional/detail/optional_config.hpp" #include "boost/optional/detail/optional_config.hpp"
#include "boost/predef.h" //#include "boost/predef.h"
#include <string> #include <string>
int main() int main()
@ -19,13 +19,13 @@ int main()
#if defined(__GNUC__) #if defined(__GNUC__)
std::string emptys; std::string emptys;
#ifdef BOOST_INTEL_CXX_VERSION #ifdef BOOST_INTEL_CXX_VERSION
BOOST_TEST_EQ(emptys, "HAS INTEL INSIDE"); BOOST_TEST_EQ(emptys, "HAS INTEL INSIDE");
#else #else
BOOST_TEST_EQ(emptys, "NO INTEL INSIDE"); BOOST_TEST_EQ(emptys, "NO INTEL INSIDE");
#endif #endif
#if !defined BOOST_NO_CXX11_RVALUE_REFERENCES #if !defined BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_TEST_EQ(emptys, "HAS RVALUE REFS"); BOOST_TEST_EQ(emptys, "HAS RVALUE REFS");
#else #else