11 #ifndef NONSTD_OPTIONAL_LITE_HPP 12 #define NONSTD_OPTIONAL_LITE_HPP 14 #define optional_lite_MAJOR 3
15 #define optional_lite_MINOR 4
16 #define optional_lite_PATCH 0
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 ) 49 #ifndef optional_CONFIG_NO_EXCEPTIONS 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
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
100 #ifndef nonstd_lite_HAVE_IN_PLACE_TYPES 101 #define nonstd_lite_HAVE_IN_PLACE_TYPES 1
112 using std::in_place_type;
113 using std::in_place_index;
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>{} 138 template< std::size_t K >
151 template< std::size_t K >
163 template< std::size_t 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> 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>=;
207 using std::make_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
282 # pragma warning( disable: 4345
) 286 # pragma warning( disable: 4814
) 291 #define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) 294 # define optional_HAS_CPP0X _HAS_CPP0X 296 # define optional_HAS_CPP0X 0
302 # undef optional_CPP11_OR_GREATER 303 # define optional_CPP11_OR_GREATER 1
323 #define optional_CPP11_110_C350_G500 364 # define optional_constexpr constexpr 366 # define optional_constexpr 370 # define optional_is_default = default; 372 # define optional_is_default {} 376 # define optional_constexpr14 constexpr 378 # define optional_constexpr14 382 # define optional_nodiscard [[nodiscard]] 384 # define optional_nodiscard 388 # define optional_noexcept noexcept 390 # define optional_noexcept 394 # define optional_nullptr nullptr 396 # define optional_nullptr NULL 401 # define optional_ref_qual & 402 # define optional_refref_qual && 404 # define optional_ref_qual 405 # define optional_refref_qual 413 # include <stdexcept> 417 # include <functional> 421 # include <initializer_list> 425 # include <type_traits> 426 #elif optional_HAVE( TR1_TYPE_TRAITS ) 427 # include <tr1/type_traits> 434 #define optional_REQUIRES_0(...) 435 template< bool B = (__VA_ARGS__), typename std::enable_if<B, int>::type = 0
> 437 #define optional_REQUIRES_T(...) 438 , typename std::enable_if< (__VA_ARGS__), int >::type = 0
440 #define optional_REQUIRES_R(R, ...) 441 typename std::enable_if< (__VA_ARGS__), R>::type 443 #define optional_REQUIRES_A(...) 444 , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr 521 using std::is_swappable;
522 using std::is_nothrow_swappable;
532 template<
typename T,
typename =
decltype( swap( std::declval<T&>(), std::declval<T&>() ) ) >
539 struct is_nothrow_swappable
543 template<
typename T >
544 static constexpr bool satisfies()
546 return noexcept( swap( std::declval<T&>(), std::declval<T&>() ) );
549 template<
typename T >
550 static auto test(
int ) -> std11::integral_constant<
bool, satisfies<T>()>{}
560 template<
typename T >
561 struct is_swappable :
decltype( detail::is_swappable::test<T>(0) ){};
563 template<
typename T >
564 struct is_nothrow_swappable :
decltype( detail::is_nothrow_swappable::test<T>(0) ){};
574 template<
typename T >
577 typedef typename std::remove_cv<
typename std::remove_reference<T>::type >::type type;
586 template<
typename T >
595 template<
typename Head,
typename Tail >
606 #define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) 607 #define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) 608 #define optional_UNIQUE3( name, line ) name ## line 610 #define optional_ALIGN_TYPE( type ) 611 type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) 613 template<
typename T >
634 #ifdef HAVE_LONG_LONG 649 #undef optional_UNIQUE 650 #undef optional_UNIQUE2 651 #undef optional_UNIQUE3 653 #undef optional_ALIGN_TYPE 655 #elif defined( optional_CONFIG_ALIGN_AS ) 659 #define optional_ALIGN_AS( unused ) 660 optional_CONFIG_ALIGN_AS 666 #define optional_ALIGN_AS( to_align ) 667 typename type_of_size< alignment_types, alignment_of< to_align >::value >::type 669 template<
typename T >
672 template<
typename T >
680 template< size_t A, size_t S >
683 enum { value = A < S ? A : S };
686 template<
typename T >
693 template<
typename List, size_t N >
708 template<
typename T>
711 #define optional_ALIGN_TYPE( type ) 712 typelist< type , typelist< struct_t< type > 738 > > > > > > > > > > > > > >
739 > > > > > > > > > > > > > >
743 #undef optional_ALIGN_TYPE 749 template<
typename T >
781 template<
class... Args >
787 template<
class... Args >
788 void emplace( Args&&... args )
793 template<
class U,
class... Args >
794 void emplace( std::initializer_list<U> il, Args&&... args )
843 aligned_storage_t data;
845 #elif optional_CONFIG_MAX_ALIGN_HACK 858 # undef optional_ALIGN_AS 872 template <
typename U>
875 return reinterpret_cast<
U*>(
ptr() );
878 template <
typename U>
881 return reinterpret_cast<
U const *>(
ptr() );
906 class bad_optional_access :
public std::logic_error
909 explicit bad_optional_access()
910 : logic_error(
"bad optional access" ) {}
917 template<
typename T>
955 if ( other.has_value() )
957 contained.construct_value( other.contained.value() );
964 template<
typename U =
T 1007 template<
typename U 1009 optional_REQUIRES_T(
1036 template<
typename U 1037 optional_REQUIRES_T(
1061 template<
typename U 1062 optional_REQUIRES_T(
1086 template<
typename...
Args 1087 optional_REQUIRES_T(
1097 template<
typename U,
typename...
Args 1098 optional_REQUIRES_T(
1108 template<
typename U =
T 1109 optional_REQUIRES_T(
1122 template<
typename U =
T 1123 optional_REQUIRES_T(
1168 optional_REQUIRES_R(
1193 optional_REQUIRES_R(
1208 template<
typename U =
T >
1210 optional_REQUIRES_R(
1234 template<
typename U >
1245 template<
typename U >
1248 optional_REQUIRES_R(
1276 template<
typename U >
1278 optional_REQUIRES_R(
1301 template<
typename...
Args 1302 optional_REQUIRES_T(
1315 template<
typename U,
typename...
Args 1316 optional_REQUIRES_T(
1448 template<
typename U >
1454 template<
typename U >
1462 template<
typename U >
1485 template<
typename V >
1494 template<
typename V >
1512 template<
typename T,
typename U >
1515 return bool(x) !=
bool(y) ?
false : !
bool( x ) ?
true : *x == *y;
1518 template<
typename T,
typename U >
1524 template<
typename T,
typename U >
1527 return (!y) ?
false : (!x) ?
true : *x < *y;
1530 template<
typename T,
typename U >
1536 template<
typename T,
typename U >
1542 template<
typename T,
typename U >
1550 template<
typename T >
1556 template<
typename T >
1562 template<
typename T >
1568 template<
typename T >
1574 template<
typename T >
1580 template<
typename T >
1586 template<
typename T >
1592 template<
typename T >
1598 template<
typename T >
1604 template<
typename T >
1610 template<
typename T >
1616 template<
typename T >
1624 template<
typename T,
typename U >
1627 return bool(x) ? *x == v :
false;
1630 template<
typename T,
typename U >
1633 return bool(x) ? v == *x :
false;
1636 template<
typename T,
typename U >
1639 return bool(x) ? *x != v :
true;
1642 template<
typename T,
typename U >
1645 return bool(x) ? v != *x :
true;
1648 template<
typename T,
typename U >
1651 return bool(x) ? *x < v :
true;
1654 template<
typename T,
typename U >
1657 return bool(x) ? v < *x :
false;
1660 template<
typename T,
typename U >
1663 return bool(x) ? *x <= v :
true;
1666 template<
typename T,
typename U >
1669 return bool(x) ? v <= *x :
false;
1672 template<
typename T,
typename U >
1675 return bool(x) ? *x > v :
false;
1678 template<
typename T,
typename U >
1681 return bool(x) ? v > *x :
true;
1684 template<
typename T,
typename U >
1687 return bool(x) ? *x >= v :
false;
1690 template<
typename T,
typename U >
1693 return bool(x) ? v >= *x :
true;
1698 template<
typename T 1700 optional_REQUIRES_T(
1707 noexcept(
noexcept(
x.
swap(
y) ) )
1715 template<
typename T >
1721 template<
typename T,
typename...
Args >
1727 template<
typename T,
typename U,
typename...
Args >
1735 template<
typename T >
1764 struct hash< nonstd::optional<T> >
1769 return bool( v ) ? std::hash<T>{}( *v ) : 0;
1777 #if defined(__clang__
) 1778 # pragma clang diagnostic pop 1779 #elif defined(__GNUC__) 1780 # pragma GCC diagnostic pop 1781 #elif defined(_MSC_VER ) 1782 # pragma warning( pop ) optional_constexpr bool operator==(U const &v, optional< T > const &x)
#define optional_CPP11_110_C350_G500
#define optional_USES_STD_OPTIONAL
optional_nodiscard U const * as() const
bool_constant< false > false_type
optional_constexpr bool operator<(U const &v, optional< T > const &x)
optional_constexpr bool operator<=(U const &v, optional< T > const &x)
#define optional_COMPILER_GNUC_VERSION
#define optional_CPP11_90
optional_nodiscard void * ptr() optional_noexcept
#define optional_ALIGN_TYPE(type)
#define optional_CONFIG_SELECT_OPTIONAL
#define optional_nodiscard
#define optional_COMPILER_MSVC_VER
#define nonstd_lite_in_place_t( T)
optional_constexpr bool operator!=(nullopt_t, optional< T > const &x) optional_noexcept
optional_constexpr bool operator==(optional< T > const &x, optional< U > const &y)
optional_constexpr bool operator==(optional< T > const &x, U const &v)
#define optional_BETWEEN(v, lo, hi)
optional_constexpr bool operator!=(optional< T > const &x, nullopt_t) optional_noexcept
optional_nodiscard U * as()
typedef optional_ALIGN_AS(value_type) align_as_type
optional< T > make_optional(T const &value)
#define optional_CPP11_110_C350
optional_constexpr bool operator>(optional< T > const &x, U const &v)
#define optional_CPP11_140_G490
in_place_t in_place(detail::in_place_index_tag< K >=detail::in_place_index_tag< K >())
optional_nodiscard void const * ptr() const optional_noexcept
#define optional_CPP11_110
storage_t() optional_is_default explicit storage_t(value_type const &v)
#define optional_CPP11_100
#define optional_OPTIONAL_NONSTD
#define optional_CPP11_140
#define optional_refref_qual
optional_constexpr bool operator<=(optional< T > const &x, U const &v)
in_place_t in_place_index(detail::in_place_index_tag< K >=detail::in_place_index_tag< K >())
void initialize(V const &value)
#define optional_STRINGIFY_(x)
void construct_value(value_type const &v)
optional_constexpr bool operator<=(nullopt_t, optional< T > const &) optional_noexcept
#define optional_STRINGIFY( x)
void(optional::* safe_bool)() const
#define optional_CONFIG_ALIGN_AS_FALLBACK
#define optional_CPP11_OR_GREATER_
optional_constexpr bool operator<=(optional< T > const &x, nullopt_t) optional_noexcept
#define optional_noexcept
#define optional_COMPILER_CLANG_VERSION
optional_constexpr bool operator<=(optional< T > const &x, optional< U > const &y)
detail::storage_t< value_type > contained
#define optional_constexpr
#define optional_CPP11_120
#define optional_CPP14_OR_GREATER
#define optional_lite_PATCH
optional_CONFIG_ALIGN_AS_FALLBACK type
optional_constexpr bool operator==(optional< T > const &x, nullopt_t) optional_noexcept
optional_constexpr bool operator>(optional< T > const &x, nullopt_t) optional_noexcept
#define optional_HAVE_STD_OPTIONAL
#define optional_HAVE(FEATURE)
#define optional_CPP11_OR_GREATER
value_type & value() optional_ref_qual
optional_constexpr14 optional(optional const &other)
optional_constexpr bool operator<(nullopt_t, optional< T > const &x) optional_noexcept
optional_constexpr bool operator>(optional< T > const &x, optional< U > const &y)
optional_constexpr bool operator<(optional< T > const &x, optional< U > const &y)
#define optional_constexpr14
optional_constexpr bool operator>(nullopt_t, optional< T > const &) optional_noexcept
#define optional_CONFIG_NO_EXCEPTIONS
optional_constexpr bool operator!=(optional< T > const &x, optional< U > const &y)
optional_nodiscard value_type const * value_ptr() const
#define optional_CPP17_000
#define optional_CPLUSPLUS
optional_constexpr bool operator<(optional< T > const &, nullopt_t) optional_noexcept
optional_constexpr bool operator<(optional< T > const &x, U const &v)
optional_constexpr bool operator>=(U const &v, optional< T > const &x)
optional_nodiscard value_type const & value() const optional_ref_qual
optional_constexpr optional(nullopt_t) optional_noexcept
optional_constexpr optional() optional_noexcept
#define optional_COMPILER_VERSION(major, minor, patch)
constexpr result_type operator()(argument_type const &arg) const
#define optional_ref_qual
optional_constexpr bool operator>=(optional< T > const &, nullopt_t) optional_noexcept
optional_constexpr bool operator>=(optional< T > const &x, U const &v)
in_place_t in_place_type(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
#define optional_OPTIONAL_DEFAULT
#define optional_lite_MINOR
optional_constexpr bool operator>=(nullopt_t, optional< T > const &x) optional_noexcept
bool_constant< true > true_type
#define optional_CONFIG_MAX_ALIGN_HACK
#define optional_CPP17_OR_GREATER
#define optional_lite_MAJOR
#define optional_is_default
#define optional_OPTIONAL_STD
#define optional_COMPILER_MSVC_VERSION
#define optional_CPP14_000
std11::conditional< N==sizeof(typename List::head), typename List::head, typename type_of_size< typename List::tail, N >::type >::type type
#define nonstd_lite_in_place( T)
optional_constexpr bool operator>=(optional< T > const &x, optional< U > const &y)
optional_constexpr bool operator!=(optional< T > const &x, U const &v)
optional_constexpr bool operator>(U const &v, optional< T > const &x)
optional_constexpr bool operator!=(U const &v, optional< T > const &x)
optional_constexpr bool operator==(nullopt_t, optional< T > const &x) optional_noexcept
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())
optional_constexpr nullopt_t(init) optional_noexcept