11 #ifndef NONSTD_OPTIONAL_LITE_HPP 12 #define NONSTD_OPTIONAL_LITE_HPP 14 #define optional_lite_MAJOR 3 15 #define optional_lite_MINOR 5 16 #define optional_lite_PATCH 0 18 #define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH) 20 #define optional_STRINGIFY( x ) optional_STRINGIFY_( x ) 21 #define optional_STRINGIFY_( x ) #x 25 #define optional_OPTIONAL_DEFAULT 0 26 #define optional_OPTIONAL_NONSTD 1 27 #define optional_OPTIONAL_STD 2 32 # if __has_include(<nonstd/optional.tweak.hpp>) 33 # include <nonstd/optional.tweak.hpp> 35 #define optional_HAVE_TWEAK_HEADER 1 37 #define optional_HAVE_TWEAK_HEADER 0 43 #if !defined( optional_CONFIG_SELECT_OPTIONAL ) 44 # define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD ) 49 #ifndef optional_CONFIG_NO_EXCEPTIONS 50 # if defined(_MSC_VER) 53 # if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) 54 # define optional_CONFIG_NO_EXCEPTIONS 0 56 # define optional_CONFIG_NO_EXCEPTIONS 1 63 #ifndef optional_CPLUSPLUS 64 # if defined(_MSVC_LANG ) && !defined(__clang__) 65 # define optional_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) 67 # define optional_CPLUSPLUS __cplusplus 71 #define optional_CPP98_OR_GREATER ( optional_CPLUSPLUS >= 199711L ) 72 #define optional_CPP11_OR_GREATER ( optional_CPLUSPLUS >= 201103L ) 73 #define optional_CPP11_OR_GREATER_ ( optional_CPLUSPLUS >= 201103L ) 74 #define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L ) 75 #define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L ) 76 #define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202000L ) 80 #define optional_CPLUSPLUS_V ( optional_CPLUSPLUS / 100 - (optional_CPLUSPLUS > 200000 ? 2000 : 1994) ) 84 #if optional_CPP17_OR_GREATER && defined(__has_include ) 85 # if __has_include( <optional> ) 86 # define optional_HAVE_STD_OPTIONAL 1 88 # define optional_HAVE_STD_OPTIONAL 0 91 # define optional_HAVE_STD_OPTIONAL 0 94 #define optional_USES_STD_OPTIONAL ( (optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_STD) || ((optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_DEFAULT) && optional_HAVE_STD_OPTIONAL) ) 100 #ifndef nonstd_lite_HAVE_IN_PLACE_TYPES 101 #define nonstd_lite_HAVE_IN_PLACE_TYPES 1 105 #if optional_CPP17_OR_GREATER 114 using std::in_place_t;
115 using std::in_place_type_t;
116 using std::in_place_index_t;
118 #define nonstd_lite_in_place_t( T) std::in_place_t 119 #define nonstd_lite_in_place_type_t( T) std::in_place_type_t<T> 120 #define nonstd_lite_in_place_index_t(K) std::in_place_index_t<K> 122 #define nonstd_lite_in_place( T) std::in_place_t{} 123 #define nonstd_lite_in_place_type( T) std::in_place_type_t<T>{} 124 #define nonstd_lite_in_place_index(K) std::in_place_index_t<K>{} 128 #else // optional_CPP17_OR_GREATER 136 struct in_place_type_tag {};
138 template< std::
size_t K >
139 struct in_place_index_tag {};
143 struct in_place_t {};
146 inline in_place_t
in_place( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
151 template< std::
size_t K >
152 inline in_place_t
in_place( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
158 inline in_place_t
in_place_type( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
163 template< std::
size_t K >
164 inline in_place_t
in_place_index( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
171 #define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> ) 172 #define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> ) 173 #define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag<K> ) 175 #define nonstd_lite_in_place( T) nonstd::in_place_type<T> 176 #define nonstd_lite_in_place_type( T) nonstd::in_place_type<T> 177 #define nonstd_lite_in_place_index(K) nonstd::in_place_index<K> 181 #endif // optional_CPP17_OR_GREATER 182 #endif // nonstd_lite_HAVE_IN_PLACE_TYPES 188 #if optional_USES_STD_OPTIONAL 195 using std::bad_optional_access;
199 using std::nullopt_t;
201 using std::operator==;
202 using std::operator!=;
203 using std::operator<;
204 using std::operator<=;
205 using std::operator>;
206 using std::operator>=;
211 #else // optional_USES_STD_OPTIONAL 218 #ifndef optional_CONFIG_MAX_ALIGN_HACK 219 # define optional_CONFIG_MAX_ALIGN_HACK 0 222 #ifndef optional_CONFIG_ALIGN_AS 226 #ifndef optional_CONFIG_ALIGN_AS_FALLBACK 227 # define optional_CONFIG_ALIGN_AS_FALLBACK double 232 #if defined(__clang__) 233 # pragma clang diagnostic push 234 # pragma clang diagnostic ignored "-Wundef" 235 #elif defined(__GNUC__) 236 # pragma GCC diagnostic push 237 # pragma GCC diagnostic ignored "-Wundef" 238 #elif defined(_MSC_VER ) 239 # pragma warning( push ) 243 #define optional_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) 259 #if defined(_MSC_VER ) && !defined(__clang__) 260 # define optional_COMPILER_MSVC_VER (_MSC_VER ) 261 # define optional_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) 263 # define optional_COMPILER_MSVC_VER 0 264 # define optional_COMPILER_MSVC_VERSION 0 267 #define optional_COMPILER_VERSION( major, minor, patch ) ( 10 * (10 * (major) + (minor) ) + (patch) ) 269 #if defined(__GNUC__) && !defined(__clang__) 270 # define optional_COMPILER_GNUC_VERSION optional_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 272 # define optional_COMPILER_GNUC_VERSION 0 275 #if defined(__clang__) 276 # define optional_COMPILER_CLANG_VERSION optional_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) 278 # define optional_COMPILER_CLANG_VERSION 0 281 #if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 140 ) 282 # pragma warning( disable: 4345 ) // initialization behavior changed 285 #if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 150 ) 286 # pragma warning( disable: 4814 ) // in C++14 'constexpr' will not imply 'const' 291 #define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) 294 # define optional_HAS_CPP0X _HAS_CPP0X 296 # define optional_HAS_CPP0X 0 301 #if optional_COMPILER_MSVC_VER >= 1900 302 # undef optional_CPP11_OR_GREATER 303 # define optional_CPP11_OR_GREATER 1 306 #define optional_CPP11_90 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1500) 307 #define optional_CPP11_100 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1600) 308 #define optional_CPP11_110 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1700) 309 #define optional_CPP11_120 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1800) 310 #define optional_CPP11_140 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1900) 311 #define optional_CPP11_141 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1910) 313 #define optional_CPP14_000 (optional_CPP14_OR_GREATER) 314 #define optional_CPP17_000 (optional_CPP17_OR_GREATER) 317 #define optional_CPP11_140_C290_G490 ((optional_CPP11_OR_GREATER_ && (optional_COMPILER_CLANG_VERSION >= 290 || optional_COMPILER_GNUC_VERSION >= 490)) || (optional_COMPILER_MSVC_VER >= 1900)) 320 #define optional_CPP11_110_C350 ( optional_CPP11_110 && !optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) ) 323 #define optional_CPP11_110_C350_G500 \ 324 ( optional_CPP11_110 && \ 325 !( optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) \ 326 || optional_BETWEEN( optional_COMPILER_GNUC_VERSION , 1, 500 ) ) ) 330 #define optional_HAVE_CONSTEXPR_11 optional_CPP11_140 331 #define optional_HAVE_IS_DEFAULT optional_CPP11_140 332 #define optional_HAVE_NOEXCEPT optional_CPP11_140 333 #define optional_HAVE_NULLPTR optional_CPP11_100 334 #define optional_HAVE_REF_QUALIFIER optional_CPP11_140_C290_G490 335 #define optional_HAVE_STATIC_ASSERT optional_CPP11_110 336 #define optional_HAVE_INITIALIZER_LIST optional_CPP11_140 340 #define optional_HAVE_CONSTEXPR_14 optional_CPP14_000 344 #define optional_HAVE_NODISCARD optional_CPP17_000 348 #define optional_HAVE_CONDITIONAL optional_CPP11_120 349 #define optional_HAVE_REMOVE_CV optional_CPP11_120 350 #define optional_HAVE_TYPE_TRAITS optional_CPP11_90 352 #define optional_HAVE_TR1_TYPE_TRAITS (!! optional_COMPILER_GNUC_VERSION ) 353 #define optional_HAVE_TR1_ADD_POINTER (!! optional_COMPILER_GNUC_VERSION ) 355 #define optional_HAVE_IS_ASSIGNABLE optional_CPP11_110_C350 356 #define optional_HAVE_IS_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 357 #define optional_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE optional_CPP11_110_C350 358 #define optional_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 359 #define optional_HAVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE optional_CPP11_110_C350_G500 360 #define optional_HAVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350_G500 364 #if optional_HAVE( CONSTEXPR_11 ) 365 # define optional_constexpr constexpr 367 # define optional_constexpr 370 #if optional_HAVE( IS_DEFAULT ) 371 # define optional_is_default = default; 373 # define optional_is_default {} 376 #if optional_HAVE( CONSTEXPR_14 ) 377 # define optional_constexpr14 constexpr 379 # define optional_constexpr14 382 #if optional_HAVE( NODISCARD ) 383 # define optional_nodiscard [[nodiscard]] 385 # define optional_nodiscard 388 #if optional_HAVE( NOEXCEPT ) 389 # define optional_noexcept noexcept 391 # define optional_noexcept 394 #if optional_HAVE( NULLPTR ) 395 # define optional_nullptr nullptr 397 # define optional_nullptr NULL 400 #if optional_HAVE( REF_QUALIFIER ) 402 # define optional_ref_qual & 403 # define optional_refref_qual && 405 # define optional_ref_qual 406 # define optional_refref_qual 409 #if optional_HAVE( STATIC_ASSERT ) 410 # define optional_static_assert(expr, text) static_assert(expr, text); 412 # define optional_static_assert(expr, text) 417 #if optional_CONFIG_NO_EXCEPTIONS 420 # include <stdexcept> 423 #if optional_CPP11_OR_GREATER 424 # include <functional> 427 #if optional_HAVE( INITIALIZER_LIST ) 428 # include <initializer_list> 431 #if optional_HAVE( TYPE_TRAITS ) 432 # include <type_traits> 433 #elif optional_HAVE( TR1_TYPE_TRAITS ) 434 # include <tr1/type_traits> 439 #if optional_CPP11_OR_GREATER 441 #define optional_REQUIRES_0(...) \ 442 template< bool B = (__VA_ARGS__), typename std::enable_if<B, int>::type = 0 > 444 #define optional_REQUIRES_T(...) \ 445 , typename std::enable_if< (__VA_ARGS__), int >::type = 0 447 #define optional_REQUIRES_R(R, ...) \ 448 typename std::enable_if< (__VA_ARGS__), R>::type 450 #define optional_REQUIRES_A(...) \ 451 , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr 459 namespace nonstd {
namespace optional_lite {
469 #if optional_CPP11_OR_GREATER 472 template<
typename T > T &
move( T & t ) {
return t; }
475 #if optional_HAVE( CONDITIONAL ) 476 using std::conditional;
479 template<
typename T,
typename F >
struct conditional<false, T, F> {
typedef F
type; };
480 #endif // optional_HAVE_CONDITIONAL 482 #if optional_HAVE( IS_ASSIGNABLE ) 483 using std::is_assignable;
488 #if optional_HAVE( IS_MOVE_CONSTRUCTIBLE ) 489 using std::is_move_constructible;
494 #if optional_HAVE( IS_NOTHROW_MOVE_ASSIGNABLE ) 495 using std::is_nothrow_move_assignable;
500 #if optional_HAVE( IS_NOTHROW_MOVE_CONSTRUCTIBLE ) 501 using std::is_nothrow_move_constructible;
506 #if optional_HAVE( IS_TRIVIALLY_COPY_CONSTRUCTIBLE ) 507 using std::is_trivially_copy_constructible;
512 #if optional_HAVE( IS_TRIVIALLY_MOVE_CONSTRUCTIBLE ) 513 using std::is_trivially_move_constructible;
520 #if optional_CPP11_OR_GREATER 526 #if optional_CPP17_OR_GREATER 528 using std::is_swappable;
529 using std::is_nothrow_swappable;
531 #elif optional_CPP11_OR_GREATER 539 template<
typename T,
typename = decltype( swap( std::declval<T&>(), std::declval<T&>() ) ) >
546 struct is_nothrow_swappable
550 template<
typename T >
551 static constexpr
bool satisfies()
553 return noexcept(
swap( std::declval<T&>(), std::declval<T&>() ) );
556 template<
typename T >
567 template<
typename T >
568 struct is_swappable : decltype( detail::is_swappable::test<T>(0) ){};
570 template<
typename T >
571 struct is_nothrow_swappable : decltype( detail::is_nothrow_swappable::test<T>(0) ){};
573 #endif // optional_CPP17_OR_GREATER 581 template<
typename T >
584 typedef typename std::remove_cv< typename std::remove_reference<T>::type >::type type;
589 #endif // optional_CPP11_OR_GREATER 593 template<
typename T >
602 template<
typename Head,
typename Tail >
609 #if optional_CONFIG_MAX_ALIGN_HACK 613 #define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) 614 #define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) 615 #define optional_UNIQUE3( name, line ) name ## line 617 #define optional_ALIGN_TYPE( type ) \ 618 type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) 620 template<
typename T >
641 #ifdef HAVE_LONG_LONG 647 Unknown ( * optional_UNIQUE(_) )( Unknown );
648 Unknown * Unknown::* optional_UNIQUE(_);
649 Unknown ( Unknown::* optional_UNIQUE(_) )( Unknown );
656 #undef optional_UNIQUE 657 #undef optional_UNIQUE2 658 #undef optional_UNIQUE3 660 #undef optional_ALIGN_TYPE 662 #elif defined( optional_CONFIG_ALIGN_AS ) // optional_CONFIG_MAX_ALIGN_HACK 666 #define optional_ALIGN_AS( unused ) \ 667 optional_CONFIG_ALIGN_AS 669 #else // optional_CONFIG_MAX_ALIGN_HACK 673 #define optional_ALIGN_AS( to_align ) \ 674 typename type_of_size< alignment_types, alignment_of< to_align >::value >::type 676 template<
typename T >
679 template<
typename T >
687 template<
size_t A,
size_t S >
690 enum {
value = A < S ? A : S };
693 template<
typename T >
700 template<
typename List,
size_t N >
704 N ==
sizeof(
typename List::head ),
715 template<
typename T>
718 #define optional_ALIGN_TYPE( type ) \ 719 typelist< type , typelist< struct_t< type > 745 > > > > > > > > > > > > > >
746 > > > > > > > > > > > > > >
750 #undef optional_ALIGN_TYPE 752 #endif // optional_CONFIG_MAX_ALIGN_HACK 756 template<
typename T >
766 explicit
storage_t( value_type const & v )
768 construct_value( v );
773 ::new( value_ptr() ) value_type( v );
776 #if optional_CPP11_OR_GREATER 783 void construct_value( value_type && v )
785 ::new( value_ptr() ) value_type(
std::move( v ) );
788 template<
class... Args >
791 emplace( std::forward<Args>(args)... );
794 template<
class... Args >
795 void emplace( Args&&... args )
797 ::new( value_ptr() ) value_type( std::forward<Args>(args)... );
800 template<
class U,
class... Args >
801 void emplace( std::initializer_list<U> il, Args&&... args )
803 ::new( value_ptr() ) value_type( il, std::forward<Args>(args)... );
815 return as<value_type>();
820 return as<value_type>();
825 return * value_ptr();
830 return * value_ptr();
833 #if optional_HAVE( REF_QUALIFIER ) 847 #if optional_CPP11_OR_GREATER 849 using aligned_storage_t =
typename std::aligned_storage< sizeof(value_type), alignof(value_type) >::type;
850 aligned_storage_t data;
852 #elif optional_CONFIG_MAX_ALIGN_HACK 854 typedef struct {
unsigned char data[
sizeof(value_type) ]; } aligned_storage_t;
857 aligned_storage_t data;
862 typedef struct { align_as_type data[ 1 + (
sizeof(value_type) - 1 ) /
sizeof(align_as_type) ]; } aligned_storage_t;
865 # undef optional_ALIGN_AS 867 #endif // optional_CONFIG_MAX_ALIGN_HACK 879 template <
typename U>
882 return reinterpret_cast<U*
>( ptr() );
885 template <
typename U>
888 return reinterpret_cast<U
const *
>( ptr() );
902 #if optional_HAVE( CONSTEXPR_11 ) 911 #if ! optional_CONFIG_NO_EXCEPTIONS 913 class bad_optional_access :
public std::logic_error
916 explicit bad_optional_access()
917 : logic_error(
"bad optional access" ) {}
920 #endif //optional_CONFIG_NO_EXCEPTIONS 924 template<
typename T>
928 "T in optional<T> must not be of type 'nullopt_t'.")
931 "T in optional<T> must not be of type 'in_place_t'.")
934 "T in optional<T> must meet the Cpp17Destructible requirements.")
937 template<
typename >
friend class optional;
939 typedef void (
optional::*safe_bool)()
const;
948 : has_value_( false )
955 : has_value_(
false )
960 #if optional_CPP11_OR_GREATER 969 : has_value_( other.has_value() )
973 contained.construct_value( other.contained.
value() );
977 #if optional_CPP11_OR_GREATER 980 template<
typename U = T
989 : has_value_( other.has_value() )
991 if ( other.has_value() )
993 contained.construct_value(
std::move( other.contained.value() ) );
1017 contained.construct_value( T{ other.contained.value() } );
1020 #endif // optional_CPP11_OR_GREATER 1023 template<
typename U
1024 #if optional_CPP11_OR_GREATER 1025 optional_REQUIRES_T(
1037 #endif // optional_CPP11_OR_GREATER 1041 : has_value_( other.has_value() )
1045 contained.construct_value( other.contained.value() );
1049 #if optional_CPP11_OR_GREATER 1052 template<
typename U
1053 optional_REQUIRES_T(
1072 contained.construct_value( T{
std::move( other.contained.value() ) } );
1077 template<
typename U
1078 optional_REQUIRES_T(
1097 contained.construct_value(
std::move( other.contained.value() ) );
1102 template<
typename... Args
1103 optional_REQUIRES_T(
1108 : has_value_(
true )
1109 , contained(
in_place, std::forward<Args>(args)... )
1113 template<
typename U,
typename... Args
1114 optional_REQUIRES_T(
1115 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::
value 1119 : has_value_(
true )
1120 , contained( T( il, std::forward<Args>(args)...) )
1124 template<
typename U = T
1125 optional_REQUIRES_T(
1128 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::
value 1133 : has_value_(
true )
1138 template<
typename U = T
1139 optional_REQUIRES_T(
1142 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::
value 1148 : has_value_(
true )
1152 #else // optional_CPP11_OR_GREATER 1156 : has_value_( true )
1157 , contained( value )
1160 #endif // optional_CPP11_OR_GREATER 1168 contained.destruct_value();
1182 #if optional_CPP11_OR_GREATER 1184 optional_REQUIRES_R(
1190 operator=( optional
const & other )
1199 if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { reset(); }
1200 else if ( (has_value() ==
false) && (other.
has_value() == true ) ) { initialize( *other ); }
1201 else if ( (has_value() ==
true ) && (other.
has_value() == true ) ) { contained.value() = *other; }
1205 #if optional_CPP11_OR_GREATER 1209 optional_REQUIRES_R(
1215 operator=( optional && other ) noexcept
1217 if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { reset(); }
1218 else if ( (has_value() ==
false) && (other.
has_value() == true ) ) { initialize(
std::move( *other ) ); }
1219 else if ( (has_value() ==
true ) && (other.
has_value() == true ) ) { contained.value() =
std::move( *other ); }
1224 template<
typename U = T >
1226 optional_REQUIRES_R(
1231 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::
value 1234 operator=( U &&
value )
1238 contained.value() = std::forward<U>(
value );
1242 initialize( T( std::forward<U>(
value ) ) );
1247 #else // optional_CPP11_OR_GREATER 1250 template<
typename U >
1253 if ( has_value() ) contained.
value() =
value;
1254 else initialize( T( value ) );
1258 #endif // optional_CPP11_OR_GREATER 1261 template<
typename U >
1262 #if optional_CPP11_OR_GREATER 1264 optional_REQUIRES_R(
1283 #endif // optional_CPP11_OR_GREATER 1286 return *
this = optional( other );
1289 #if optional_CPP11_OR_GREATER 1292 template<
typename U >
1294 optional_REQUIRES_R(
1313 return *
this = optional(
std::move( other ) );
1317 template<
typename... Args
1318 optional_REQUIRES_T(
1322 T& emplace( Args&&... args )
1325 contained.emplace( std::forward<Args>(args)... );
1327 return contained.value();
1331 template<
typename U,
typename... Args
1332 optional_REQUIRES_T(
1333 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::
value 1336 T& emplace( std::initializer_list<U> il, Args&&... args )
1339 contained.emplace( il, std::forward<Args>(args)... );
1341 return contained.value();
1344 #endif // optional_CPP11_OR_GREATER 1349 #if optional_CPP11_OR_GREATER 1357 if ( (has_value() ==
true ) && (other.
has_value() == true ) ) {
swap( **
this, *other ); }
1358 else if ( (has_value() ==
false) && (other.
has_value() == true ) ) { initialize(
std11::move(*other) ); other.
reset(); }
1359 else if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { other.initialize(
std11::move(**
this) ); reset(); }
1366 return assert( has_value() ),
1367 contained.value_ptr();
1372 return assert( has_value() ),
1373 contained.value_ptr();
1378 return assert( has_value() ),
1384 return assert( has_value() ),
1388 #if optional_HAVE( REF_QUALIFIER ) 1402 #if optional_CPP11_OR_GREATER 1410 return has_value() ? &optional::this_type_does_not_support_comparisons : 0;
1423 #if optional_CONFIG_NO_EXCEPTIONS 1424 assert( has_value() );
1426 if ( ! has_value() )
1428 throw bad_optional_access();
1431 return contained.value();
1436 #if optional_CONFIG_NO_EXCEPTIONS 1437 assert( has_value() );
1439 if ( ! has_value() )
1441 throw bad_optional_access();
1444 return contained.value();
1447 #if optional_HAVE( REF_QUALIFIER ) && ( !optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490 ) 1462 #if optional_HAVE( REF_QUALIFIER ) 1464 template<
typename U >
1467 return has_value() ? contained.value() :
static_cast<T
>(std::forward<U>( v ) );
1470 template<
typename U >
1473 #if optional_COMPILER_CLANG_VERSION 1474 return has_value() ? ( contained.value() ) : static_cast<T>(std::forward<U>( v ) );
1476 return has_value() ?
std::move( contained.value() ) : static_cast<T>(std::forward<U>( v ) );
1482 template<
typename U >
1485 return has_value() ? contained.value() :
static_cast<value_type
>( v );
1488 #endif // optional_CPP11_OR_GREATER 1496 contained.destruct_value();
1503 void this_type_does_not_support_comparisons()
const {}
1505 template<
typename V >
1506 void initialize( V
const &
value )
1508 assert( ! has_value() );
1509 contained.construct_value( value );
1513 #if optional_CPP11_OR_GREATER 1514 template<
typename V >
1515 void initialize( V && value )
1517 assert( ! has_value() );
1518 contained.construct_value(
std::move( value ) );
1532 template<
typename T,
typename U >
1535 return bool(x) != bool(y) ? false : !bool( x ) ? true : *x == *y;
1538 template<
typename T,
typename U >
1544 template<
typename T,
typename U >
1547 return (!y) ? false : (!x) ?
true : *x < *y;
1550 template<
typename T,
typename U >
1556 template<
typename T,
typename U >
1562 template<
typename T,
typename U >
1570 template<
typename T >
1576 template<
typename T >
1582 template<
typename T >
1588 template<
typename T >
1594 template<
typename T >
1600 template<
typename T >
1606 template<
typename T >
1612 template<
typename T >
1618 template<
typename T >
1624 template<
typename T >
1630 template<
typename T >
1636 template<
typename T >
1644 template<
typename T,
typename U >
1647 return bool(x) ? *x == v :
false;
1650 template<
typename T,
typename U >
1653 return bool(x) ? v == *x :
false;
1656 template<
typename T,
typename U >
1659 return bool(x) ? *x != v :
true;
1662 template<
typename T,
typename U >
1665 return bool(x) ? v != *x :
true;
1668 template<
typename T,
typename U >
1671 return bool(x) ? *x < v :
true;
1674 template<
typename T,
typename U >
1677 return bool(x) ? v < *x :
false;
1680 template<
typename T,
typename U >
1683 return bool(x) ? *x <= v :
true;
1686 template<
typename T,
typename U >
1689 return bool(x) ? v <= *x :
false;
1692 template<
typename T,
typename U >
1695 return bool(x) ? *x > v :
false;
1698 template<
typename T,
typename U >
1701 return bool(x) ? v > *x :
true;
1704 template<
typename T,
typename U >
1707 return bool(x) ? *x >= v :
false;
1710 template<
typename T,
typename U >
1713 return bool(x) ? v >= *x :
true;
1718 template<
typename T
1719 #if optional_CPP11_OR_GREATER 1720 optional_REQUIRES_T(
1726 #if optional_CPP11_OR_GREATER 1727 noexcept( noexcept( x.
swap(y) ) )
1733 #if optional_CPP11_OR_GREATER 1735 template<
typename T >
1741 template<
typename T,
typename...Args >
1747 template<
typename T,
typename U,
typename... Args >
1755 template<
typename T >
1761 #endif // optional_CPP11_OR_GREATER 1769 #if ! optional_CONFIG_NO_EXCEPTIONS 1770 using optional_lite::bad_optional_access;
1777 #if optional_CPP11_OR_GREATER 1784 struct hash< nonstd::optional<T> >
1789 return bool( v ) ? std::hash<T>{}( *v ) : 0;
1795 #endif // optional_CPP11_OR_GREATER 1797 #if defined(__clang__) 1798 # pragma clang diagnostic pop 1799 #elif defined(__GNUC__) 1800 # pragma GCC diagnostic pop 1801 #elif defined(_MSC_VER ) 1802 # pragma warning( pop ) 1805 #endif // optional_USES_STD_OPTIONAL 1807 #endif // NONSTD_OPTIONAL_LITE_HPP optional_constexpr bool operator==(U const &v, optional< T > const &x)
optional_nodiscard U const * as() const
bool_constant< false > false_type
#define optional_noexcept
optional_constexpr bool operator<(U const &v, optional< T > const &x)
optional_constexpr bool operator<=(U const &v, optional< T > const &x)
#define optional_refref_qual
#define nonstd_lite_in_place_t( T)
optional_nodiscard void * ptr() optional_noexcept
span_CONFIG_SIZE_TYPE size_t
#define optional_constexpr
void swap(optional< T > &x, optional< T > &y)
optional_nodiscard U * as()
optional_constexpr14 value_type & value() optional_ref_qual
optional< T > make_optional(T const &value)
#define optional_ref_qual
optional_constexpr14 value_type const & value() const optional_ref_qual
optional_nodiscard void const * ptr() const optional_noexcept
storage_t() optional_is_default explicit storage_t(value_type const &v)
void reset() optional_noexcept
optional & operator=(nullopt_t) optional_noexcept
optional_CONFIG_ALIGN_AS_FALLBACK type
in_place_t in_place_index(detail::in_place_index_tag< K >=detail::in_place_index_tag< K >())
optional(value_type const &value)
void construct_value(value_type const &v)
optional & operator=(U const &value)
optional & operator=(optional< U > const &other)
#define optional_nodiscard
value_type & value() optional_ref_qual
optional_constexpr14 optional(optional const &other)
#define optional_ALIGN_AS(to_align)
optional_constexpr value_type value_or(U const &v) const
optional_nodiscard value_type const * value_ptr() const
#define optional_static_assert(expr, text)
optional_constexpr bool operator>=(U const &v, optional< T > const &x)
optional_nodiscard value_type const & value() const optional_ref_qual
void swap(optional &other)
optional_constexpr optional(nullopt_t) optional_noexcept
optional_constexpr optional() optional_noexcept
optional(optional< U > const &other)
optional & operator=(optional const &other)
#define optional_ALIGN_TYPE(type)
#define nonstd_lite_in_place( T)
in_place_t in_place_type(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
bool_constant< true > true_type
std11::conditional< N==sizeof(typename List::head), typename List::head, typename type_of_size< typename List::tail, N >::type >::type type
#define optional_is_default
C++03 constructed union to hold value.
optional_constexpr bool operator>(U const &v, optional< T > const &x)
const nullopt_t nullopt((nullopt_t::init()))
#define optional_constexpr14
Unit testing utility error code.
optional_constexpr bool operator!=(U const &v, optional< T > const &x)
#define optional_CONFIG_ALIGN_AS_FALLBACK
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
optional_constexpr nullopt_t(init) optional_noexcept
optional_constexpr bool has_value() const optional_noexcept