932 : has_value_( false )
939 : has_value_(
false )
944#if optional_CPP11_OR_GREATER
953 : has_value_( other.has_value() )
961#if optional_CPP11_OR_GREATER
964 template<
typename U = T
973 : has_value_( other.has_value() )
975 if ( other.has_value() )
977 contained.construct_value( std::move( other.contained.value() ) );
984 std::is_constructible<T, U const &>::value
985 && !std::is_constructible<T, optional<U> & >::value
986 && !std::is_constructible<T, optional<U> && >::value
987 && !std::is_constructible<T, optional<U>
const & >::value
988 && !std::is_constructible<T, optional<U>
const && >::value
989 && !std::is_convertible< optional<U> & , T>::value
990 && !std::is_convertible< optional<U> && , T>::value
991 && !std::is_convertible< optional<U>
const & , T>::value
992 && !std::is_convertible< optional<U>
const &&, T>::value
993 && !std::is_convertible< U const & , T>::value
996 explicit optional( optional<U>
const & other )
997 : has_value_( other.has_value() )
999 if ( other.has_value() )
1001 contained.construct_value( T{ other.contained.value() } );
1007 template<
typename U
1008#if optional_CPP11_OR_GREATER
1009 optional_REQUIRES_T(
1010 std::is_constructible<T, U const &>::value
1011 && !std::is_constructible<T, optional<U> & >::value
1012 && !std::is_constructible<T, optional<U> && >::value
1013 && !std::is_constructible<T, optional<U>
const & >::value
1014 && !std::is_constructible<T, optional<U>
const && >::value
1015 && !std::is_convertible< optional<U> & , T>::value
1016 && !std::is_convertible< optional<U> && , T>::value
1017 && !std::is_convertible< optional<U>
const & , T>::value
1018 && !std::is_convertible< optional<U>
const &&, T>::value
1019 && std::is_convertible< U const & , T>::value
1025 : has_value_( other.has_value() )
1033#if optional_CPP11_OR_GREATER
1036 template<
typename U
1037 optional_REQUIRES_T(
1038 std::is_constructible<T, U &&>::value
1039 && !std::is_constructible<T,
optional<U> & >::value
1040 && !std::is_constructible<T,
optional<U> && >::value
1041 && !std::is_constructible<T,
optional<U> const & >::value
1042 && !std::is_constructible<T,
optional<U> const && >::value
1043 && !std::is_convertible<
optional<U> & , T>::value
1044 && !std::is_convertible<
optional<U> && , T>::value
1045 && !std::is_convertible<
optional<U> const & , T>::value
1046 && !std::is_convertible<
optional<U> const &&, T>::value
1047 && !std::is_convertible< U &&, T>::value
1052 : has_value_( other.has_value() )
1054 if ( other.has_value() )
1056 contained.construct_value( T{ std::move( other.contained.value() ) } );
1061 template<
typename U
1062 optional_REQUIRES_T(
1063 std::is_constructible<T, U &&>::value
1064 && !std::is_constructible<T, optional<U> & >::value
1065 && !std::is_constructible<T, optional<U> && >::value
1066 && !std::is_constructible<T, optional<U>
const & >::value
1067 && !std::is_constructible<T, optional<U>
const && >::value
1068 && !std::is_convertible< optional<U> & , T>::value
1069 && !std::is_convertible< optional<U> && , T>::value
1070 && !std::is_convertible< optional<U>
const & , T>::value
1071 && !std::is_convertible< optional<U>
const &&, T>::value
1072 && std::is_convertible< U &&, T>::value
1076 optional( optional<U> && other )
1077 : has_value_( other.has_value() )
1079 if ( other.has_value() )
1081 contained.construct_value( std::move( other.contained.value() ) );
1086 template<
typename... Args
1087 optional_REQUIRES_T(
1088 std::is_constructible<T, Args&&...>::value
1092 : has_value_( true )
1093 , contained( T(
std::forward<Args>(args)...) )
1097 template<
typename U,
typename... Args
1098 optional_REQUIRES_T(
1099 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value
1103 : has_value_( true )
1104 , contained( T( il,
std::forward<Args>(args)...) )
1108 template<
typename U = T
1109 optional_REQUIRES_T(
1110 std::is_constructible<T, U&&>::value
1112 && !std::is_same<
typename std20::remove_cvref<U>::type, optional<T>>::value
1113 && !std::is_convertible<U&&, T>::value
1117 : has_value_( true )
1122 template<
typename U = T
1123 optional_REQUIRES_T(
1124 std::is_constructible<T, U&&>::value
1126 && !std::is_same<
typename std20::remove_cvref<U>::type, optional<T>>::value
1127 && std::is_convertible<U&&, T>::value
1132 : has_value_( true )
1140 : has_value_( true )
1141 , contained( value )
1152 contained.destruct_value();
1166#if optional_CPP11_OR_GREATER
1168 optional_REQUIRES_R(
1176 std11::is_nothrow_move_assignable<T>::value
1177 && std11::is_nothrow_move_constructible<T>::value
1183 if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { reset(); }
1184 else if ( (has_value() ==
false) && (other.
has_value() ==
true ) ) { initialize( *other ); }
1185 else if ( (has_value() ==
true ) && (other.
has_value() ==
true ) ) { contained.value() = *other; }
1189#if optional_CPP11_OR_GREATER
1193 optional_REQUIRES_R(
1199 operator=(
optional && other ) noexcept
1201 if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { reset(); }
1202 else if ( (has_value() ==
false) && (other.
has_value() ==
true ) ) { initialize( std::move( *other ) ); }
1203 else if ( (has_value() ==
true ) && (other.
has_value() ==
true ) ) { contained.value() = std::move( *other ); }
1208 template<
typename U = T >
1210 optional_REQUIRES_R(
1212 std::is_constructible<T , U>::value
1213 && std11::is_assignable<T&, U>::value
1215 && !std::is_same<
typename std20::remove_cvref<U>::type, optional<T>>::value
1216 && !(std::is_scalar<T>::value && std::is_same<T,
typename std::decay<U>::type>::value)
1218 operator=( U && value )
1222 contained.value() = std::forward<U>( value );
1226 initialize( T( std::forward<U>( value ) ) );
1234 template<
typename U >
1237 if ( has_value() ) contained.
value() = value;
1238 else initialize( T( value ) );
1245 template<
typename U >
1246#if optional_CPP11_OR_GREATER
1248 optional_REQUIRES_R(
1250 std::is_constructible< T , U const &>::value
1252 && !std::is_constructible<T,
optional<U> & >::value
1253 && !std::is_constructible<T,
optional<U> && >::value
1254 && !std::is_constructible<T,
optional<U> const & >::value
1255 && !std::is_constructible<T,
optional<U> const && >::value
1256 && !std::is_convertible<
optional<U> & , T>::value
1257 && !std::is_convertible<
optional<U> && , T>::value
1258 && !std::is_convertible<
optional<U> const & , T>::value
1259 && !std::is_convertible<
optional<U> const &&, T>::value
1273#if optional_CPP11_OR_GREATER
1276 template<
typename U >
1278 optional_REQUIRES_R(
1280 std::is_constructible< T , U>::value
1282 && !std::is_constructible<T,
optional<U> & >::value
1283 && !std::is_constructible<T,
optional<U> && >::value
1284 && !std::is_constructible<T,
optional<U> const & >::value
1285 && !std::is_constructible<T,
optional<U> const && >::value
1286 && !std::is_convertible<
optional<U> & , T>::value
1287 && !std::is_convertible<
optional<U> && , T>::value
1288 && !std::is_convertible<
optional<U> const & , T>::value
1289 && !std::is_convertible<
optional<U> const &&, T>::value
1297 return *
this =
optional( std::move( other ) );
1301 template<
typename... Args
1302 optional_REQUIRES_T(
1303 std::is_constructible<T, Args&&...>::value
1306 T& emplace( Args&&... args )
1309 contained.emplace( std::forward<Args>(args)... );
1311 return contained.value();
1315 template<
typename U,
typename... Args
1316 optional_REQUIRES_T(
1317 std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value
1320 T& emplace( std::initializer_list<U> il, Args&&... args )
1323 contained.emplace( il, std::forward<Args>(args)... );
1325 return contained.value();
1333#if optional_CPP11_OR_GREATER
1336 && std17::is_nothrow_swappable<T>::value
1341 if ( (has_value() ==
true ) && (other.
has_value() == true ) ) {
swap( **
this, *other ); }
1342 else if ( (has_value() ==
false) && (other.
has_value() ==
true ) ) { initialize( std11::move(*other) ); other.
reset(); }
1343 else if ( (has_value() ==
true ) && (other.
has_value() ==
false) ) { other.
initialize( std11::move(**
this) ); reset(); }
1350 return assert( has_value() ),
1351 contained.value_ptr();
1356 return assert( has_value() ),
1357 contained.value_ptr();
1362 return assert( has_value() ),
1368 return assert( has_value() ),
1372#if optional_HAVE( REF_QUALIFIER )
1376 return std::move( **
this );
1381 return std::move( **
this );
1386#if optional_CPP11_OR_GREATER
1394 return has_value() ? &optional::this_type_does_not_support_comparisons : 0;
1407#if optional_CONFIG_NO_EXCEPTIONS
1408 assert( has_value() );
1410 if ( ! has_value() )
1412 throw bad_optional_access();
1415 return contained.value();
1420#if optional_CONFIG_NO_EXCEPTIONS
1421 assert( has_value() );
1423 if ( ! has_value() )
1425 throw bad_optional_access();
1428 return contained.value();
1431#if optional_HAVE( REF_QUALIFIER ) && ( !optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490 )
1436 return std::move( value() );
1441 return std::move( value() );
1446#if optional_CPP11_OR_GREATER
1448 template<
typename U >
1451 return has_value() ? contained.value() :
static_cast<T
>(std::forward<U>( v ) );
1454 template<
typename U >
1457 return has_value() ? std::move( contained.value() ) : static_cast<T>(
std::forward<U>(
v ) );
1462 template<
typename U >
1465 return has_value() ? contained.value() :
static_cast<value_type>( v );
1476 contained.destruct_value();
1485 template<
typename V >
1488 assert( ! has_value() );
1489 contained.construct_value( value );
1493#if optional_CPP11_OR_GREATER
1494 template<
typename V >
1495 void initialize( V && value )
1497 assert( ! has_value() );
1498 contained.construct_value( std::move( value ) );