12# ifndef STX_OPTIONAL_HPP_INCLUDED
13# define STX_OPTIONAL_HPP_INCLUDED
15#ifndef STX_NAMESPACE_NAME
16#define STX_NAMESPACE_NAME stx
20#if !defined(STX_NO_STD_OPTIONAL) && defined(__APPLE__)
23#if defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION <= 4000)
24#define STX_NO_STD_OPTIONAL
29#if !defined(STX_NO_STD_OPTIONAL) && defined(__GNUC__) && (__cplusplus < 201402)
30#define STX_NO_STD_OPTIONAL
33#if defined(__has_include) && !defined(STX_NO_STD_OPTIONAL)
34# if __has_include(<optional>) && (__cplusplus > 201402)
36 namespace STX_NAMESPACE_NAME {
38 using std::bad_optional_access;
41 using std::make_optional;
42 using std::in_place_t;
45# define STX_HAVE_STD_OPTIONAL 1
49#ifndef STX_HAVE_STD_OPTIONAL
53# include <type_traits>
54# include <initializer_list>
60# define TR2_OPTIONAL_REQUIRES(...) typename std::enable_if<__VA_ARGS__::value, bool>::type = false
63# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
64# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
66# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
69# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)
70# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
72# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
75# if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1)
76# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
77# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)
78# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
80# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
84# if defined __clang_major__
85# if (__clang_major__ == 3 && __clang_minor__ >= 5)
86# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
87# elif (__clang_major__ > 3)
88# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
90# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
91# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
92# elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2)
93# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
98# if (_MSC_VER >= 1900)
99# define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
103# if defined __clang__
104# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9)
105# define OPTIONAL_HAS_THIS_RVALUE_REFS 1
107# define OPTIONAL_HAS_THIS_RVALUE_REFS 0
109# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
110# define OPTIONAL_HAS_THIS_RVALUE_REFS 1
111# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
112# define OPTIONAL_HAS_THIS_RVALUE_REFS 1
114# define OPTIONAL_HAS_THIS_RVALUE_REFS 0
118# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
119# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1
120# define OPTIONAL_CONSTEXPR_INIT_LIST constexpr
122# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0
123# define OPTIONAL_CONSTEXPR_INIT_LIST
126# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L)
127# define OPTIONAL_HAS_MOVE_ACCESSORS 1
129# define OPTIONAL_HAS_MOVE_ACCESSORS 0
133# if (defined __cplusplus) && (__cplusplus == 201103L)
134# define OPTIONAL_MUTABLE_CONSTEXPR
136# define OPTIONAL_MUTABLE_CONSTEXPR constexpr
139namespace STX_NAMESPACE_NAME {
142# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
144# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
146# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
148# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
151 template <
typename T>
152 using is_trivially_destructible = std::has_trivial_destructor<T>;
156# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___)
158# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
160# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
162# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
171 constexpr static bool value = std::is_nothrow_constructible<T, T&&>::value;
175template <
class T,
class U>
178 template <
class X,
class Y>
179 constexpr static bool has_assign(...) {
return false; }
181 template <class X, class Y, size_t S = sizeof((std::declval<X>() = std::declval<Y>(),
true)) >
183 constexpr static bool has_assign(
bool) {
return true; }
185 constexpr static bool value = has_assign<T, U>(
true);
192 template <
class X,
bool has_any_move_assign>
194 constexpr static bool value =
false;
199 constexpr static bool value =
noexcept( std::declval<X&>() = std::declval<X&&>() );
215template <
class T>
class optional<T&>;
219template <
class T>
inline constexpr T&& constexpr_forward(
typename std::remove_reference<T>::type& t)
noexcept
221 return static_cast<T&&
>(t);
224template <
class T>
inline constexpr T&& constexpr_forward(
typename std::remove_reference<T>::type&& t)
noexcept
226 static_assert(!std::is_lvalue_reference<T>::value,
"!!");
227 return static_cast<T&&
>(t);
230template <
class T>
inline constexpr typename std::remove_reference<T>::type&& constexpr_move(T&& t)
noexcept
232 return static_cast<typename std::remove_reference<T>::type&&
>(t);
237# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
239# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR)))
251 constexpr static bool has_overload(...) {
return false; }
253 template <class X, size_t S = sizeof(std::declval<X&>().operator&()) >
254 constexpr static bool has_overload(
bool) {
return true; }
256 constexpr static bool value = has_overload<T>(
true);
259template <
typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
260constexpr T* static_addressof(T& ref)
265template <
typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)>
266T* static_addressof(T& ref)
268 return std::addressof(ref);
274constexpr U convert(U v) {
return v; }
283#ifndef STX_HAVE_IN_PLACE_T
301#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304
305constexpr in_place_index_t<I> in_place_index{};
309#define STX_HAVE_IN_PLACE_T
318constexpr nullopt_t nullopt{nullopt_t::init()};
332 unsigned char dummy_;
337 template <
class... Args>
338 constexpr storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {}
347 unsigned char dummy_;
352 template <
class... Args>
353 constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {}
365 constexpr optional_base() noexcept : init_(
false), storage_(trivial_init) {};
368 explicit constexpr optional_base(
const T& v) : init_(
true), storage_(v) {}
371 explicit constexpr optional_base(T&& v) : init_(
true), storage_(constexpr_move(v)) {}
374 : init_(
true), storage_(constexpr_forward<Args>(args)...) {}
376 template <
class U,
class... Args, TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
378 : init_(
true), storage_(il, std::forward<Args>(args)...) {}
399 : init_(
true), storage_(constexpr_forward<Args>(args)...) {}
401 template <
class U,
class... Args, TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
403 : init_(
true), storage_(il, std::forward<Args>(args)...) {}
409using OptionalBase =
typename std::conditional<
410 std::is_trivially_destructible<T>::value,
420 static_assert( !std::is_same<typename std::decay<T>::type,
nullopt_t>::value,
"bad T" );
421 static_assert( !std::is_same<typename std::decay<T>::type,
in_place_t>::value,
"bad T" );
424 constexpr bool initialized()
const noexcept {
return OptionalBase<T>::init_; }
425 typename std::remove_const<T>::type* dataptr() {
return std::addressof(OptionalBase<T>::storage_.value_); }
426 constexpr const T* dataptr()
const {
return detail_::static_addressof(OptionalBase<T>::storage_.value_); }
428# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
429 constexpr const T& contained_val()
const& {
return OptionalBase<T>::storage_.value_; }
430# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
431 OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && {
return std::move(OptionalBase<T>::storage_.value_); }
432 OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & {
return OptionalBase<T>::storage_.value_; }
434 T& contained_val() & {
return OptionalBase<T>::storage_.value_; }
435 T&& contained_val() && {
return std::move(OptionalBase<T>::storage_.value_); }
438 constexpr const T& contained_val()
const {
return OptionalBase<T>::storage_.value_; }
439 T& contained_val() {
return OptionalBase<T>::storage_.value_; }
442 void clear()
noexcept {
443 if (initialized()) dataptr()->T::~T();
444 OptionalBase<T>::init_ =
false;
447 template <
class... Args>
448 void initialize(Args&&... args)
noexcept(
noexcept(T(std::forward<Args>(args)...)))
450 assert(!OptionalBase<T>::init_);
451 ::new (
static_cast<void*
>(dataptr())) T(std::forward<Args>(args)...);
452 OptionalBase<T>::init_ =
true;
455 template <
class U,
class... Args>
456 void initialize(std::initializer_list<U> il, Args&&... args)
noexcept(
noexcept(T(il, std::forward<Args>(args)...)))
458 assert(!OptionalBase<T>::init_);
459 ::new (
static_cast<void*
>(dataptr())) T(il, std::forward<Args>(args)...);
460 OptionalBase<T>::init_ =
true;
464 typedef T value_type;
467 constexpr optional() noexcept : OptionalBase<T>() {};
474 if (rhs.initialized()) {
475 ::new (
static_cast<void*
>(dataptr())) T(*rhs);
476 OptionalBase<T>::init_ =
true;
480 optional(
optional&& rhs)
noexcept(std::is_nothrow_move_constructible<T>::value)
483 if (rhs.initialized()) {
484 ::new (
static_cast<void*
>(dataptr())) T(std::move(*rhs));
485 OptionalBase<T>::init_ =
true;
490 explicit constexpr optional(
const T& v) : OptionalBase<T>(v) {}
493 explicit constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {}
495 template <
class... Args>
497 : OptionalBase<T>(
in_place_t{}, constexpr_forward<Args>(args)...) {}
499 template <
class U,
class... Args, TR2_OPTIONAL_REQUIRES(std::is_constructible<T, std::initializer_list<U>>)>
500 OPTIONAL_CONSTEXPR_INIT_LIST
explicit optional(
in_place_t, std::initializer_list<U> il, Args&&... args)
501 : OptionalBase<T>(
in_place_t{}, il, constexpr_forward<Args>(args)...) {}
515 if (initialized() ==
true && rhs.initialized() ==
false) clear();
516 else if (initialized() ==
false && rhs.initialized() ==
true) initialize(*rhs);
517 else if (initialized() ==
true && rhs.initialized() ==
true) contained_val() = *rhs;
522 noexcept(std::is_nothrow_move_assignable<T>::value && std::is_nothrow_move_constructible<T>::value)
524 if (initialized() ==
true && rhs.initialized() ==
false) clear();
525 else if (initialized() ==
false && rhs.initialized() ==
true) initialize(std::move(*rhs));
526 else if (initialized() ==
true && rhs.initialized() ==
true) contained_val() = std::move(*rhs);
531 auto operator=(U&& v)
532 ->
typename std::enable_if
534 std::is_same<typename std::decay<U>::type, T>::value,
538 if (initialized()) { contained_val() = std::forward<U>(v); }
539 else { initialize(std::forward<U>(v)); }
544 template <
class... Args>
545 void emplace(Args&&... args)
548 initialize(std::forward<Args>(args)...);
551 template <
class U,
class... Args>
552 void emplace(std::initializer_list<U> il, Args&&... args)
555 initialize<U, Args...>(il, std::forward<Args>(args)...);
559 void swap(
optional<T>& rhs)
noexcept(std::is_nothrow_move_constructible<T>::value &&
noexcept(swap(std::declval<T&>(), std::declval<T&>())))
561 if (initialized() ==
true && rhs.initialized() ==
false) { rhs.initialize(std::move(**
this)); clear(); }
562 else if (initialized() ==
false && rhs.initialized() ==
true) { initialize(std::move(*rhs)); rhs.clear(); }
563 else if (initialized() ==
true && rhs.initialized() ==
true) {
using std::swap; swap(**
this, *rhs); }
568 explicit constexpr operator bool()
const noexcept {
return initialized(); }
569 constexpr bool has_value()
const noexcept {
return initialized(); }
571 constexpr T
const* operator ->()
const {
572 return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());
575# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
577 OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() {
578 assert (initialized());
582 constexpr T
const& operator *()
const& {
583 return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
586 OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & {
587 assert (initialized());
588 return contained_val();
591 OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && {
592 assert (initialized());
593 return constexpr_move(contained_val());
596 constexpr T
const& value()
const& {
597 return initialized() ? contained_val() : (
throw bad_optional_access(
"bad optional access"), contained_val());
600 OPTIONAL_MUTABLE_CONSTEXPR T& value() & {
601 return initialized() ? contained_val() : (
throw bad_optional_access(
"bad optional access"), contained_val());
604 OPTIONAL_MUTABLE_CONSTEXPR T&& value() && {
606 return std::move(contained_val());
612 assert (initialized());
616 constexpr T
const& operator *()
const {
617 return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
621 assert (initialized());
622 return contained_val();
625 constexpr T
const& value()
const {
627 return initialized() ? contained_val() : (
throw bad_optional_access(
"bad optional access"), contained_val());
631 return initialized() ? contained_val() : (
throw bad_optional_access(
"bad optional access"), contained_val());
636# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
639 constexpr T value_or(V&& v)
const&
641 return *
this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
644# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
647 OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) &&
649 return *
this ? constexpr_move(
const_cast<optional<T>&
>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
657 return *
this ? constexpr_move(
const_cast<optional<T>&
>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
665 constexpr T value_or(V&& v)
const
667 return *
this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
673 void reset()
noexcept { clear(); }
680 static_assert( !std::is_same<T, nullopt_t>::value,
"bad T" );
681 static_assert( !std::is_same<T, in_place_t>::value,
"bad T" );
687 constexpr optional() noexcept : ref(
nullptr) {}
693 explicit constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {}
699 explicit constexpr optional(
in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) {}
726 template <
typename U>
727 auto operator=(U&& rhs)
noexcept
728 ->
typename std::enable_if
730 std::is_same<typename std::decay<U>::type,
optional<T&>>::value,
738 template <
typename U>
739 auto operator=(U&& rhs)
noexcept
740 ->
typename std::enable_if
742 !std::is_same<typename std::decay<U>::type,
optional<T&>>::value,
747 void emplace(T& v)
noexcept {
748 ref = detail_::static_addressof(v);
751 void emplace(T&&) =
delete;
756 std::swap(ref, rhs.ref);
760 constexpr T* operator->()
const {
761 return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);
764 constexpr T& operator*()
const {
765 return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);
768 constexpr T& value()
const {
775 explicit constexpr operator bool()
const noexcept {
776 return ref !=
nullptr;
779 constexpr bool has_value()
const noexcept {
780 return ref !=
nullptr;
784 constexpr typename std::decay<T>::type value_or(V&& v)
const
786 return *
this ? **this : detail_::convert<typename std::decay<T>::type>(constexpr_forward<V>(v));
790 void reset()
noexcept { ref =
nullptr; }
797 static_assert(
sizeof(T) == 0,
"optional rvalue references disallowed" );
804 return bool(x) != bool(y) ? false : bool(x) ==
false ? true : *x == *y;
807template <
class T>
constexpr bool operator!=(
const optional<T>& x,
const optional<T>& y)
812template <
class T>
constexpr bool operator<(
const optional<T>& x,
const optional<T>& y)
814 return (!y) ? false : (!x) ?
true : *x < *y;
817template <
class T>
constexpr bool operator>(
const optional<T>& x,
const optional<T>& y)
822template <
class T>
constexpr bool operator<=(
const optional<T>& x,
const optional<T>& y)
827template <
class T>
constexpr bool operator>=(
const optional<T>& x,
const optional<T>& y)
834template <
class T>
constexpr bool operator==(
const optional<T>& x, nullopt_t)
noexcept
839template <
class T>
constexpr bool operator==(nullopt_t,
const optional<T>& x)
noexcept
844template <
class T>
constexpr bool operator!=(
const optional<T>& x, nullopt_t)
noexcept
849template <
class T>
constexpr bool operator!=(nullopt_t,
const optional<T>& x)
noexcept
854template <
class T>
constexpr bool operator<(
const optional<T>&, nullopt_t)
noexcept
859template <
class T>
constexpr bool operator<(nullopt_t,
const optional<T>& x)
noexcept
864template <
class T>
constexpr bool operator<=(
const optional<T>& x, nullopt_t)
noexcept
869template <
class T>
constexpr bool operator<=(nullopt_t,
const optional<T>&)
noexcept
874template <
class T>
constexpr bool operator>(
const optional<T>& x, nullopt_t)
noexcept
879template <
class T>
constexpr bool operator>(nullopt_t,
const optional<T>&)
noexcept
884template <
class T>
constexpr bool operator>=(
const optional<T>&, nullopt_t)
noexcept
889template <
class T>
constexpr bool operator>=(nullopt_t,
const optional<T>& x)
noexcept
897template <
class T>
constexpr bool operator==(
const optional<T>& x,
const T& v)
899 return bool(x) ? *x == v :
false;
902template <
class T>
constexpr bool operator==(
const T& v,
const optional<T>& x)
904 return bool(x) ? v == *x :
false;
907template <
class T>
constexpr bool operator!=(
const optional<T>& x,
const T& v)
909 return bool(x) ? *x != v :
true;
912template <
class T>
constexpr bool operator!=(
const T& v,
const optional<T>& x)
914 return bool(x) ? v != *x :
true;
917template <
class T>
constexpr bool operator<(
const optional<T>& x,
const T& v)
919 return bool(x) ? *x < v :
true;
922template <
class T>
constexpr bool operator>(
const T& v,
const optional<T>& x)
924 return bool(x) ? v > *x :
true;
927template <
class T>
constexpr bool operator>(
const optional<T>& x,
const T& v)
929 return bool(x) ? *x > v :
false;
932template <
class T>
constexpr bool operator<(
const T& v,
const optional<T>& x)
934 return bool(x) ? v < *x :
false;
937template <
class T>
constexpr bool operator>=(
const optional<T>& x,
const T& v)
939 return bool(x) ? *x >= v :
false;
942template <
class T>
constexpr bool operator<=(
const T& v,
const optional<T>& x)
944 return bool(x) ? v <= *x :
false;
947template <
class T>
constexpr bool operator<=(
const optional<T>& x,
const T& v)
949 return bool(x) ? *x <= v :
true;
952template <
class T>
constexpr bool operator>=(
const T& v,
const optional<T>& x)
954 return bool(x) ? v >= *x :
true;
959template <
class T>
constexpr bool operator==(
const optional<T&>& x,
const T& v)
961 return bool(x) ? *x == v :
false;
964template <
class T>
constexpr bool operator==(
const T& v,
const optional<T&>& x)
966 return bool(x) ? v == *x :
false;
969template <
class T>
constexpr bool operator!=(
const optional<T&>& x,
const T& v)
971 return bool(x) ? *x != v :
true;
974template <
class T>
constexpr bool operator!=(
const T& v,
const optional<T&>& x)
976 return bool(x) ? v != *x :
true;
979template <
class T>
constexpr bool operator<(
const optional<T&>& x,
const T& v)
981 return bool(x) ? *x < v :
true;
984template <
class T>
constexpr bool operator>(
const T& v,
const optional<T&>& x)
986 return bool(x) ? v > *x :
true;
989template <
class T>
constexpr bool operator>(
const optional<T&>& x,
const T& v)
991 return bool(x) ? *x > v :
false;
994template <
class T>
constexpr bool operator<(
const T& v,
const optional<T&>& x)
996 return bool(x) ? v < *x :
false;
999template <
class T>
constexpr bool operator>=(
const optional<T&>& x,
const T& v)
1001 return bool(x) ? *x >= v :
false;
1004template <
class T>
constexpr bool operator<=(
const T& v,
const optional<T&>& x)
1006 return bool(x) ? v <= *x :
false;
1009template <
class T>
constexpr bool operator<=(
const optional<T&>& x,
const T& v)
1011 return bool(x) ? *x <= v :
true;
1014template <
class T>
constexpr bool operator>=(
const T& v,
const optional<T&>& x)
1016 return bool(x) ? v >= *x :
true;
1020template <
class T>
constexpr bool operator==(
const optional<const T&>& x,
const T& v)
1022 return bool(x) ? *x == v :
false;
1025template <
class T>
constexpr bool operator==(
const T& v,
const optional<const T&>& x)
1027 return bool(x) ? v == *x :
false;
1030template <
class T>
constexpr bool operator!=(
const optional<const T&>& x,
const T& v)
1032 return bool(x) ? *x != v :
true;
1035template <
class T>
constexpr bool operator!=(
const T& v,
const optional<const T&>& x)
1037 return bool(x) ? v != *x :
true;
1040template <
class T>
constexpr bool operator<(
const optional<const T&>& x,
const T& v)
1042 return bool(x) ? *x < v :
true;
1045template <
class T>
constexpr bool operator>(
const T& v,
const optional<const T&>& x)
1047 return bool(x) ? v > *x :
true;
1050template <
class T>
constexpr bool operator>(
const optional<const T&>& x,
const T& v)
1052 return bool(x) ? *x > v :
false;
1055template <
class T>
constexpr bool operator<(
const T& v,
const optional<const T&>& x)
1057 return bool(x) ? v < *x :
false;
1060template <
class T>
constexpr bool operator>=(
const optional<const T&>& x,
const T& v)
1062 return bool(x) ? *x >= v :
false;
1065template <
class T>
constexpr bool operator<=(
const T& v,
const optional<const T&>& x)
1067 return bool(x) ? v <= *x :
false;
1070template <
class T>
constexpr bool operator<=(
const optional<const T&>& x,
const T& v)
1072 return bool(x) ? *x <= v :
true;
1075template <
class T>
constexpr bool operator>=(
const T& v,
const optional<const T&>& x)
1077 return bool(x) ? v >= *x :
true;
1083void swap(optional<T>& x, optional<T>& y)
noexcept(
noexcept(x.swap(y)))
1090constexpr optional<typename std::decay<T>::type> make_optional(T&& v)
1092 return optional<typename std::decay<T>::type>(constexpr_forward<T>(v));
1096constexpr optional<X&> make_optional(std::reference_wrapper<X> v)
1098 return optional<X&>(v.get());
1106 template <
typename T>
1107 struct hash<STX_NAMESPACE_NAME::optional<T>>
1109 typedef typename hash<T>::result_type result_type;
1112 constexpr result_type operator()(
argument_type const& arg)
const {
1113 return arg ? std::hash<T>{}(*arg) : result_type{};
1117 template <
typename T>
1118 struct hash<STX_NAMESPACE_NAME::optional<T&>>
1120 typedef typename hash<T>::result_type result_type;
1123 constexpr result_type operator()(
argument_type const& arg)
const {
1124 return arg ? std::hash<T>{}(*arg) : result_type{};
1129# undef TR2_OPTIONAL_REQUIRES
1130# undef TR2_OPTIONAL_ASSERTED_EXPRESSION
Definition: optional.hpp:322
Definition: optional.hpp:679
Definition: optional.hpp:419
Definition: optional.hpp:386
Definition: optional.hpp:249
Definition: optional.hpp:296
Definition: optional.hpp:285
Definition: optional.hpp:291
Definition: optional.hpp:177
Definition: optional.hpp:193
Definition: optional.hpp:191
Definition: optional.hpp:170
Definition: optional.hpp:315
Definition: optional.hpp:314
Definition: optional.hpp:361
Definition: optional.hpp:279
Definition: optional.hpp:346
Definition: optional.hpp:331