11 #ifndef NONSTD_OPTIONAL_LITE_HPP 12 #define NONSTD_OPTIONAL_LITE_HPP 14 #define optional_lite_MAJOR 3 15 #define optional_lite_MINOR 1 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 29 #if !defined( optional_CONFIG_SELECT_OPTIONAL ) 30 # define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD ) 36 #ifndef optional_CPLUSPLUS 38 # define optional_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) 40 # define optional_CPLUSPLUS __cplusplus 44 #define optional_CPP98_OR_GREATER ( optional_CPLUSPLUS >= 199711L ) 45 #define optional_CPP11_OR_GREATER ( optional_CPLUSPLUS >= 201103L ) 46 #define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L ) 47 #define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L ) 48 #define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202000L ) 52 #define optional_CPLUSPLUS_V ( optional_CPLUSPLUS / 100 - (optional_CPLUSPLUS > 200000 ? 2000 : 1994) ) 56 #if optional_CPP17_OR_GREATER && defined(__has_include ) 57 # if __has_include( <optional> ) 58 # define optional_HAVE_STD_OPTIONAL 1 60 # define optional_HAVE_STD_OPTIONAL 0 63 # define optional_HAVE_STD_OPTIONAL 0 66 #define optional_USES_STD_OPTIONAL ( (optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_STD) || ((optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_DEFAULT) && optional_HAVE_STD_OPTIONAL) ) 70 #if optional_USES_STD_OPTIONAL 77 using std::bad_optional_access;
85 using std::in_place_t;
86 using std::in_place_type_t;
87 using std::in_place_index_t;
89 using std::operator==;
90 using std::operator!=;
92 using std::operator<=;
94 using std::operator>=;
99 #else // optional_USES_STD_OPTIONAL 107 #ifndef optional_CONFIG_MAX_ALIGN_HACK 108 # define optional_CONFIG_MAX_ALIGN_HACK 0 111 #ifndef optional_CONFIG_ALIGN_AS 115 #ifndef optional_CONFIG_ALIGN_AS_FALLBACK 116 # define optional_CONFIG_ALIGN_AS_FALLBACK double 121 #if defined (__clang__) 122 # pragma clang diagnostic push 123 # pragma clang diagnostic ignored "-Wundef" 124 #elif defined (__GNUC__) 125 # pragma GCC diagnostic push 126 # pragma GCC diagnostic ignored "-Wundef" 130 #define optional_BETWEEN( v, lo, hi ) ( lo <= v && v < hi ) 132 #if defined(_MSC_VER) && !defined(__clang__) 133 # define optional_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900)) ) 135 # define optional_COMPILER_MSVC_VERSION 0 138 #define optional_COMPILER_VERSION( major, minor, patch ) ( 10 * (10 * major + minor ) + patch ) 140 #if defined (__GNUC__) && !defined(__clang__) 141 # define optional_COMPILER_GNUC_VERSION optional_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 143 # define optional_COMPILER_GNUC_VERSION 0 146 #if defined (__clang__) 147 # define optional_COMPILER_CLANG_VERSION optional_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) 149 # define optional_COMPILER_CLANG_VERSION 0 152 #if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 140 ) 153 # pragma warning( push ) 154 # pragma warning( disable: 4345 ) // initialization behavior changed 157 #if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 150 ) 158 # pragma warning( push ) 159 # pragma warning( disable: 4814 ) // in C++14 'constexpr' will not imply 'const' 164 #define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) 168 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 100 169 # define optional_HAVE_AUTO 1 170 # define optional_HAVE_NULLPTR 1 171 # define optional_HAVE_STATIC_ASSERT 1 174 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 120 175 # define optional_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 1 176 # define optional_HAVE_INITIALIZER_LIST 1 179 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 140 180 # define optional_HAVE_ALIAS_TEMPLATE 1 181 # define optional_HAVE_CONSTEXPR_11 1 182 # define optional_HAVE_ENUM_CLASS 1 183 # define optional_HAVE_EXPLICIT_CONVERSION 1 184 # define optional_HAVE_IS_DEFAULT 1 185 # define optional_HAVE_IS_DELETE 1 186 # define optional_HAVE_NOEXCEPT 1 187 # define optional_HAVE_REF_QUALIFIER 1 192 #if optional_CPP14_OR_GREATER 193 # define optional_HAVE_CONSTEXPR_14 1 198 #if optional_CPP17_OR_GREATER 199 # define optional_HAVE_ENUM_CLASS_CONSTRUCTION_FROM_UNDERLYING_TYPE 1 204 #if optional_COMPILER_GNUC_VERSION 205 # define optional_HAVE_TR1_TYPE_TRAITS 1 206 # define optional_HAVE_TR1_ADD_POINTER 1 209 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 90 210 # define optional_HAVE_TYPE_TRAITS 1 211 # define optional_HAVE_STD_ADD_POINTER 1 214 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 110 215 # define optional_HAVE_ARRAY 1 218 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 120 219 # define optional_HAVE_CONDITIONAL 1 222 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 140 || (optional_COMPILER_MSVC_VERSION >= 90 && _HAS_CPP0X) 223 # define optional_HAVE_CONTAINER_DATA_METHOD 1 226 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 120 227 # define optional_HAVE_REMOVE_CV 1 230 #if optional_CPP11_OR_GREATER || optional_COMPILER_MSVC_VERSION >= 140 231 # define optional_HAVE_SIZED_TYPES 1 236 #if optional_COMPILER_MSVC_VERSION >= 140 237 # undef optional_CPP11_OR_GREATER 238 # define optional_CPP11_OR_GREATER 1 243 #if optional_HAVE( CONSTEXPR_11 ) 244 # define optional_constexpr constexpr 246 # define optional_constexpr 249 #if optional_HAVE( CONSTEXPR_14 ) 250 # define optional_constexpr14 constexpr 252 # define optional_constexpr14 255 #if optional_HAVE( NOEXCEPT ) 256 # define optional_noexcept noexcept 258 # define optional_noexcept 261 #if optional_HAVE( NULLPTR ) 262 # define optional_nullptr nullptr 264 # define optional_nullptr NULL 267 #if optional_HAVE( REF_QUALIFIER ) 268 # define optional_ref_qual & 269 # define optional_refref_qual && 271 # define optional_ref_qual 272 # define optional_refref_qual 277 #if optional_CPP11_OR_GREATER 278 # include <functional> 281 #if optional_HAVE( INITIALIZER_LIST ) 282 # include <initializer_list> 285 #if optional_HAVE( TYPE_TRAITS ) 286 # include <type_traits> 287 #elif optional_HAVE( TR1_TYPE_TRAITS ) 288 # include <tr1/type_traits> 293 #if optional_CPP11_OR_GREATER 295 # define optional_REQUIRES_T(...) \ 296 , typename = typename std::enable_if<__VA_ARGS__>::type 298 # define optional_REQUIRES_R(R, ...) \ 299 typename std::enable_if<__VA_ARGS__, R>::type 301 # define optional_REQUIRES_A(...) \ 302 , typename std::enable_if<__VA_ARGS__, void*>::type = optional_nullptr 310 #ifndef nonstd_lite_HAVE_IN_PLACE_TYPES 311 #define nonstd_lite_HAVE_IN_PLACE_TYPES 1 315 #if optional_CPP17_OR_GREATER 322 using std::in_place_t;
323 using std::in_place_type_t;
324 using std::in_place_index_t;
326 #define nonstd_lite_in_place_t( T) std::in_place_t 327 #define nonstd_lite_in_place_type_t( T) std::in_place_type_t<T> 328 #define nonstd_lite_in_place_index_t(T) std::in_place_index_t<I> 330 #define nonstd_lite_in_place( T) std::in_place_t{} 331 #define nonstd_lite_in_place_type( T) std::in_place_type_t<T>{} 332 #define nonstd_lite_in_place_index(T) std::in_place_index_t<I>{} 336 #else // optional_CPP17_OR_GREATER 344 template< std::
size_t I >
357 template< std::
size_t I >
369 template< std::
size_t I >
377 #define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> ) 378 #define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> ) 379 #define nonstd_lite_in_place_index_t(T) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag<I> ) 381 #define nonstd_lite_in_place( T) nonstd::in_place_type<T> 382 #define nonstd_lite_in_place_type( T) nonstd::in_place_type<T> 383 #define nonstd_lite_in_place_index(T) nonstd::in_place_index<I> 387 #endif // optional_CPP17_OR_GREATER 388 #endif // nonstd_lite_HAVE_IN_PLACE_TYPES 394 namespace nonstd {
namespace optional_lite {
398 #if optional_HAVE( CONDITIONAL ) 399 using std::conditional;
402 template<
typename T,
typename F >
struct conditional<false, T, F> {
typedef F
type; };
403 #endif // optional_HAVE_CONDITIONAL 407 #if optional_CPP11_OR_GREATER 413 template<
typename T >
416 typedef typename std::remove_cv< typename std::remove_reference<T>::type >
::type type;
421 #endif // optional_CPP11_OR_GREATER 425 template<
typename T >
434 template<
typename Head,
typename Tail >
441 #if optional_CONFIG_MAX_ALIGN_HACK 445 #define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) 446 #define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) 447 #define optional_UNIQUE3( name, line ) name ## line 449 #define optional_ALIGN_TYPE( type ) \ 450 type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) 452 template<
typename T >
473 #ifdef HAVE_LONG_LONG 479 Unknown ( * optional_UNIQUE(_) )( Unknown );
480 Unknown * Unknown::* optional_UNIQUE(_);
481 Unknown ( Unknown::* optional_UNIQUE(_) )( Unknown );
488 #undef optional_UNIQUE 489 #undef optional_UNIQUE2 490 #undef optional_UNIQUE3 492 #undef optional_ALIGN_TYPE 494 #elif defined( optional_CONFIG_ALIGN_AS ) // optional_CONFIG_MAX_ALIGN_HACK 498 #define optional_ALIGN_AS( unused ) \ 499 optional_CONFIG_ALIGN_AS 501 #else // optional_CONFIG_MAX_ALIGN_HACK 505 #define optional_ALIGN_AS( to_align ) \ 506 typename type_of_size< alignment_types, alignment_of< to_align >::value >::type 508 template<
typename T >
511 template<
typename T >
519 template<
size_t A,
size_t S >
522 enum { value = A < S ? A : S };
525 template<
typename T >
532 template<
typename List,
size_t N >
536 N ==
sizeof(
typename List::head ),
547 template<
typename T>
550 #define optional_ALIGN_TYPE( type ) \ 551 typelist< type , typelist< struct_t< type > 577 > > > > > > > > > > > > > >
578 > > > > > > > > > > > > > >
582 #undef optional_ALIGN_TYPE 584 #endif // optional_CONFIG_MAX_ALIGN_HACK 588 template<
typename T >
600 construct_value( v );
605 ::new( value_ptr() ) value_type( v );
608 #if optional_CPP11_OR_GREATER 612 construct_value( std::move( v ) );
615 void construct_value( value_type && v )
617 ::new( value_ptr() ) value_type( std::move( v ) );
620 template<
class... Args >
621 void emplace( Args&&... args )
623 ::new( value_ptr() ) value_type( std::forward<Args>(args)... );
626 template<
class U,
class... Args >
627 void emplace( std::initializer_list<U> il, Args&&... args )
629 ::new( value_ptr() ) value_type( il, std::forward<Args>(args)... );
641 return as<value_type>();
646 return as<value_type>();
651 return * value_ptr();
656 return * value_ptr();
659 #if optional_CPP11_OR_GREATER 663 return std::move( value() );
668 return std::move( value() );
673 #if optional_CPP11_OR_GREATER 675 using aligned_storage_t =
typename std::aligned_storage< sizeof(value_type), alignof(value_type) >::type;
676 aligned_storage_t data;
678 #elif optional_CONFIG_MAX_ALIGN_HACK 680 typedef struct {
unsigned char data[
sizeof(value_type) ]; } aligned_storage_t;
683 aligned_storage_t data;
688 typedef struct { align_as_type data[ 1 + (
sizeof(value_type) - 1 ) /
sizeof(align_as_type) ]; } aligned_storage_t;
691 # undef optional_ALIGN_AS 693 #endif // optional_CONFIG_MAX_ALIGN_HACK 705 template <
typename U>
708 return reinterpret_cast<U*
>( ptr() );
711 template <
typename U>
714 return reinterpret_cast<U
const *
>( ptr() );
728 #if optional_HAVE( CONSTEXPR_11 ) 741 : logic_error(
"bad optional access" ) {}
746 template<
typename T>
752 typedef void (
optional::*safe_bool)()
const;
761 : has_value_( false )
767 : has_value_( false )
775 true || std::is_copy_constructible<T>::value
779 : has_value_( other.has_value() )
781 if ( other.has_value() )
782 contained.construct_value( other.contained.value() );
785 #if optional_CPP11_OR_GREATER 790 true || std::is_move_constructible<T>::value
792 ) noexcept( std::is_nothrow_move_constructible<T>::value )
793 : has_value_( other.has_value() )
795 if ( other.has_value() )
796 contained.construct_value( std::move( other.contained.value() ) );
800 template<
typename U >
803 std::is_constructible<T, U const &>::value
804 && !std::is_constructible<T,
optional<U> & >::value
805 && !std::is_constructible<T,
optional<U> && >::value
806 && !std::is_constructible<T,
optional<U> const & >::value
807 && !std::is_constructible<T,
optional<U> const && >::value
809 && !std::is_convertible<
optional<U> && , T>::value
810 && !std::is_convertible<
optional<U> const & , T>::value
811 && !std::is_convertible<
optional<U> const &&, T>::value
812 && !std::is_convertible< U const & , T>::value
815 : has_value_( other.has_value() )
817 if ( other.has_value() )
818 contained.construct_value( other.contained.value() );
820 #endif // optional_CPP11_OR_GREATER 823 template<
typename U >
827 std::is_constructible<T, U const &>::value
828 && !std::is_constructible<T,
optional<U> & >::value
829 && !std::is_constructible<T,
optional<U> && >::value
830 && !std::is_constructible<T,
optional<U> const & >::value
831 && !std::is_constructible<T,
optional<U> const && >::value
833 && !std::is_convertible<
optional<U> && , T>::value
834 && !std::is_convertible<
optional<U> const & , T>::value
835 && !std::is_convertible<
optional<U> const &&, T>::value
836 && std::is_convertible< U const & , T>::value
840 : has_value_( other.has_value() )
842 if ( other.has_value() )
843 contained.construct_value( other.contained.value() );
846 #if optional_CPP11_OR_GREATER 849 template<
typename U >
852 std::is_constructible<T, U const &>::value
853 && !std::is_constructible<T,
optional<U> & >::value
854 && !std::is_constructible<T,
optional<U> && >::value
855 && !std::is_constructible<T,
optional<U> const & >::value
856 && !std::is_constructible<T,
optional<U> const && >::value
858 && !std::is_convertible<
optional<U> && , T>::value
859 && !std::is_convertible<
optional<U> const & , T>::value
860 && !std::is_convertible<
optional<U> const &&, T>::value
861 && !std::is_convertible< U &&, T>::value
864 : has_value_( other.has_value() )
866 if ( other.has_value() )
867 contained.construct_value( std::move( other.contained.value() ) );
871 template<
typename U >
874 std::is_constructible<T, U const &>::value
875 && !std::is_constructible<T,
optional<U> & >::value
876 && !std::is_constructible<T,
optional<U> && >::value
877 && !std::is_constructible<T,
optional<U> const & >::value
878 && !std::is_constructible<T,
optional<U> const && >::value
880 && !std::is_convertible<
optional<U> && , T>::value
881 && !std::is_convertible<
optional<U> const & , T>::value
882 && !std::is_convertible<
optional<U> const &&, T>::value
883 && std::is_convertible< U &&, T>::value
886 : has_value_( other.has_value() )
888 if ( other.has_value() )
889 contained.construct_value( std::move( other.contained.value() ) );
893 template<
typename... Args
895 std::is_constructible<T, Args&&...>::value
900 , contained( T( std::forward<Args>(args)...) )
904 template<
typename U,
typename... Args
906 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value
911 , contained( T( il, std::forward<Args>(args)...) )
915 template<
typename U = value_type >
918 std::is_constructible<T, U&&>::value
920 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::value
921 && !std::is_convertible<U&&, T>::value
925 , contained( std::forward<U>( value ) )
929 template<
typename U = value_type >
932 std::is_constructible<T, U&&>::value
934 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::value
935 && std::is_convertible<U&&, T>::value
939 , contained( std::forward<U>( value ) )
942 #else // optional_CPP11_OR_GREATER 950 #endif // optional_CPP11_OR_GREATER 957 contained.destruct_value();
970 #if optional_CPP11_OR_GREATER 977 operator=( optional
const & other )
979 std::is_nothrow_move_assignable<T>::value
980 && std::is_nothrow_move_constructible<T>::value
986 if ( has_value() ==
true && other.
has_value() == false ) reset();
987 else if ( has_value() ==
false && other.
has_value() == true ) initialize( *other );
988 else if ( has_value() ==
true && other.
has_value() == true ) contained.
value() = *other;
992 #if optional_CPP11_OR_GREATER 1001 operator=( optional && other ) noexcept
1003 if ( has_value() ==
true && other.
has_value() == false ) reset();
1004 else if ( has_value() ==
false && other.
has_value() == true ) initialize( std::move( *other ) );
1005 else if ( has_value() ==
true && other.
has_value() == true ) contained.
value() = std::move( *other );
1010 template<
typename U = T >
1011 optional_REQUIRES_R(
1013 std::is_constructible<T , U>::value
1014 && std::is_assignable<T&, U>::value
1016 && !std::is_same<
typename std20::remove_cvref<U>::type,
optional<T>>::value
1019 operator=( U && value )
1021 if ( has_value() ) contained.value() = std::forward<U>( value );
1022 else initialize( T( std::forward<U>( value ) ) );
1026 #else // optional_CPP11_OR_GREATER 1029 template<
typename U >
1032 if ( has_value() ) contained.
value() = value;
1033 else initialize( T( value ) );
1037 #endif // optional_CPP11_OR_GREATER 1040 template<
typename U >
1041 #if optional_CPP11_OR_GREATER 1042 optional_REQUIRES_R(
1044 std::is_constructible< T , U const &>::value
1045 && std::is_assignable< T&, U const &>::value
1046 && !std::is_constructible<T,
optional<U> & >::value
1047 && !std::is_constructible<T,
optional<U> && >::value
1048 && !std::is_constructible<T,
optional<U> const & >::value
1049 && !std::is_constructible<T,
optional<U> const && >::value
1050 && !std::is_convertible<
optional<U> & , T>::value
1051 && !std::is_convertible<
optional<U> && , T>::value
1052 && !std::is_convertible<
optional<U> const & , T>::value
1053 && !std::is_convertible<
optional<U> const &&, T>::value
1054 && !std::is_assignable< T&,
optional<U> & >::value
1055 && !std::is_assignable< T&,
optional<U> && >::value
1056 && !std::is_assignable< T&,
optional<U> const & >::value
1057 && !std::is_assignable< T&,
optional<U> const && >::value
1061 #endif // optional_CPP11_OR_GREATER 1064 return *
this = optional( other );
1067 #if optional_CPP11_OR_GREATER 1070 template<
typename U >
1071 optional_REQUIRES_R(
1073 std::is_constructible< T , U>::value
1074 && std::is_assignable< T&, U>::value
1075 && !std::is_constructible<T,
optional<U> & >::value
1076 && !std::is_constructible<T,
optional<U> && >::value
1077 && !std::is_constructible<T,
optional<U> const & >::value
1078 && !std::is_constructible<T,
optional<U> const && >::value
1079 && !std::is_convertible<
optional<U> & , T>::value
1080 && !std::is_convertible<
optional<U> && , T>::value
1081 && !std::is_convertible<
optional<U> const & , T>::value
1082 && !std::is_convertible<
optional<U> const &&, T>::value
1083 && !std::is_assignable< T&,
optional<U> & >::value
1084 && !std::is_assignable< T&,
optional<U> && >::value
1085 && !std::is_assignable< T&,
optional<U> const & >::value
1086 && !std::is_assignable< T&,
optional<U> const && >::value
1090 return *
this = optional( std::move( other ) );
1094 template<
typename... Args
1095 optional_REQUIRES_T(
1096 std::is_constructible<T, Args&&...>::value
1099 T& emplace( Args&&... args )
1102 contained.emplace( std::forward<Args>(args)... );
1104 return contained.value();
1108 template<
typename U,
typename... Args
1109 optional_REQUIRES_T(
1110 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value
1113 T& emplace( std::initializer_list<U> il, Args&&... args )
1116 contained.emplace( il, std::forward<Args>(args)... );
1118 return contained.value();
1121 #endif // optional_CPP11_OR_GREATER 1126 #if optional_CPP11_OR_GREATER 1128 std::is_nothrow_move_constructible<T>::value
1129 && noexcept(
std::swap( std::declval<T&>(), std::declval<T&>() ) )
1134 if ( has_value() ==
true && other.
has_value() == true ) {
swap( **
this, *other ); }
1135 else if ( has_value() ==
false && other.
has_value() == true ) { initialize( *other ); other.
reset(); }
1136 else if ( has_value() ==
true && other.
has_value() == false ) { other.initialize( **
this ); reset(); }
1143 return assert( has_value() ),
1144 contained.value_ptr();
1149 return assert( has_value() ),
1150 contained.value_ptr();
1155 return assert( has_value() ),
1161 return assert( has_value() ),
1165 #if optional_CPP11_OR_GREATER 1169 return std::move( **
this );
1174 return std::move( **
this );
1179 #if optional_CPP11_OR_GREATER 1187 return has_value() ? &optional::this_type_does_not_support_comparisons : 0;
1198 if ( ! has_value() )
1201 return contained.value();
1206 if ( ! has_value() )
1209 return contained.value();
1212 #if optional_HAVE( REF_QUALIFIER ) 1216 return std::move( value() );
1221 return std::move( value() );
1226 #if optional_CPP11_OR_GREATER 1228 template<
typename U >
1231 return has_value() ? contained.value() :
static_cast<T
>(std::forward<U>( v ) );
1234 template<
typename U >
1237 return has_value() ? std::move( contained.value() ) : static_cast<T>(std::forward<U>( v ) );
1242 template<
typename U >
1245 return has_value() ? contained.value() :
static_cast<value_type
>( v );
1248 #endif // optional_CPP11_OR_GREATER 1255 contained.destruct_value();
1261 void this_type_does_not_support_comparisons()
const {}
1263 template<
typename V >
1264 void initialize( V
const & value )
1266 assert( ! has_value() );
1267 contained.construct_value( value );
1271 #if optional_CPP11_OR_GREATER 1272 template<
typename V >
1273 void initialize( V && value )
1275 assert( ! has_value() );
1276 contained.construct_value( std::move( value ) );
1290 template<
typename T,
typename U >
1293 return bool(x) != bool(y) ?
false : !bool( x ) ?
true : *x == *y;
1296 template<
typename T,
typename U >
1302 template<
typename T,
typename U >
1305 return (!y) ?
false : (!x) ?
true : *x < *y;
1308 template<
typename T,
typename U >
1314 template<
typename T,
typename U >
1320 template<
typename T,
typename U >
1328 template<
typename T >
1334 template<
typename T >
1340 template<
typename T >
1346 template<
typename T >
1352 template<
typename T >
1358 template<
typename T >
1364 template<
typename T >
1370 template<
typename T >
1376 template<
typename T >
1382 template<
typename T >
1388 template<
typename T >
1394 template<
typename T >
1402 template<
typename T,
typename U >
1405 return bool(x) ? *x == v :
false;
1408 template<
typename T,
typename U >
1411 return bool(x) ? v == *x :
false;
1414 template<
typename T,
typename U >
1417 return bool(x) ? *x != v :
true;
1420 template<
typename T,
typename U >
1423 return bool(x) ? v != *x :
true;
1426 template<
typename T,
typename U >
1429 return bool(x) ? *x < v :
true;
1432 template<
typename T,
typename U >
1435 return bool(x) ? v < *x :
false;
1438 template<
typename T,
typename U >
1441 return bool(x) ? *x <= v :
true;
1444 template<
typename T,
typename U >
1447 return bool(x) ? v <= *x :
false;
1450 template<
typename T,
typename U >
1453 return bool(x) ? *x > v :
false;
1456 template<
typename T,
typename U >
1459 return bool(x) ? v > *x :
true;
1462 template<
typename T,
typename U >
1465 return bool(x) ? *x >= v :
false;
1468 template<
typename T,
typename U >
1471 return bool(x) ? v >= *x :
true;
1476 template<
typename T >
1478 #if optional_CPP11_OR_GREATER 1479 noexcept( noexcept( x.
swap(y) ) )
1485 #if optional_CPP11_OR_GREATER 1487 template<
typename T >
1493 template<
typename T,
typename...Args >
1499 template<
typename T,
typename U,
typename... Args >
1507 template<
typename T >
1513 #endif // optional_CPP11_OR_GREATER 1517 using namespace optional_lite;
1521 #if optional_CPP11_OR_GREATER 1528 struct hash< nonstd::optional<T> >
1533 return bool( v ) ? hash<T>()( *v ) : 0;
1539 #endif // optional_CPP11_OR_GREATER 1541 #if defined (__clang__) 1542 # pragma clang diagnostic pop 1543 #elif defined (__GNUC__) 1544 # pragma GCC diagnostic pop 1547 #endif // optional_USES_STD_OPTIONAL 1549 #endif // NONSTD_OPTIONAL_LITE_HPP
#define nonstd_lite_in_place_t(T)
bool operator>(U const &v, optional< T > const &x)
in_place_t in_place_index(detail::in_place_index_tag< I >=detail::in_place_index_tag< I >())
conditional< N==sizeof(typename List::head), typename List::head, typename type_of_size< typename List::tail, N >::type >::type type
type_of_size< alignment_types, alignment_of< value_type >::value >::type align_as_type
#define optional_noexcept
#define optional_ref_qual
void swap(optional< T > &x, optional< T > &y)
optional< T > make_optional(T const &value)
bool operator==(U const &v, optional< T > const &x)
optional(optional const &other)
typelist< char, typelist< struct_t< char >, typelist< short, typelist< struct_t< short >, typelist< int, typelist< struct_t< int >, typelist< long, typelist< struct_t< long >, typelist< float, typelist< struct_t< float >, typelist< double, typelist< struct_t< double >, typelist< long double, typelist< struct_t< long double >, typelist< char *, typelist< struct_t< char * >, typelist< short *, typelist< struct_t< short * >, typelist< int *, typelist< struct_t< int * >, typelist< long *, typelist< struct_t< long * >, typelist< float *, typelist< struct_t< float * >, typelist< double *, typelist< struct_t< double * >, typelist< long double *, typelist< struct_t< long double * >, typelist< Unknown(*)(Unknown), typelist< struct_t< Unknown(*)(Unknown) >, typelist< Unknown *Unknown::*, typelist< struct_t< Unknown *Unknown::* >, typelist< Unknown(Unknown::*)(Unknown), typelist< struct_t< Unknown(Unknown::*)(Unknown) >, nulltype > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > alignment_types
value_type const & value() const
value_type value_or(U const &v) const
optional & operator=(nullopt_t)
optional(value_type const &value)
void construct_value(value_type const &v)
value_type const * value_ptr() const
optional & operator=(U const &value)
optional & operator=(optional< U > const &other)
storage_t(value_type const &v)
#define optional_CONFIG_ALIGN_AS_FALLBACK
#define optional_refref_qual
bool operator!=(U const &v, optional< T > const &x)
#define optional_CPP11_OR_GREATER
void swap(optional &other)
#define nonstd_lite_in_place(T)
#define optional_ALIGN_TYPE(type)
optional(optional< U > const &other)
#define optional_constexpr14
optional & operator=(optional const &other)
in_place_t in_place_type(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
in_place_t in_place(detail::in_place_index_tag< I >=detail::in_place_index_tag< I >())
C++03 constructed union to hold value.
bool operator>=(U const &v, optional< T > const &x)
#define optional_ALIGN_AS(to_align)
const nullopt_t nullopt((nullopt_t::init()))
#define optional_constexpr
value_type const & value() const
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())