Lines Matching full:optional

14     optional synopsis
19 // [optional.optional], class template optional
21 class optional;
24 concept is-derived-from-optional = requires(const T& t) { // exposition only
25 []<class U>(const optional<U>&){ }(t);
28 // [optional.nullopt], no-value state indicator
32 // [optional.bad.access], class bad_optional_access
35 // [optional.relops], relational operators
37 constexpr bool operator==(const optional<T>&, const optional<U>&);
39 constexpr bool operator!=(const optional<T>&, const optional<U>&);
41 constexpr bool operator<(const optional<T>&, const optional<U>&);
43 constexpr bool operator>(const optional<T>&, const optional<U>&);
45 constexpr bool operator<=(const optional<T>&, const optional<U>&);
47 constexpr bool operator>=(const optional<T>&, const optional<U>&);
50 operator<=>(const optional<T>&, const optional<U>&); // since C++20
52 // [optional.nullops], comparison with nullopt
53 template<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
54 …template<class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept; // until C++17
55 …template<class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept; // until C++17
56 …template<class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept; // until C++17
57 …template<class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept; // until C++17
58 …template<class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept; // until C++17
59 …template<class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept; // until C++17
60 …template<class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept; // until C++17
61 …template<class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept; // until C++17
62 …template<class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept; // until C++17
63 …template<class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept; // until C++17
64 …template<class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept; // until C++17
66 … constexpr strong_ordering operator<=>(const optional<T>&, nullopt_t) noexcept; // since C++20
68 // [optional.comp.with.t], comparison with T
69 template<class T, class U> constexpr bool operator==(const optional<T>&, const U&);
70 template<class T, class U> constexpr bool operator==(const T&, const optional<U>&);
71 template<class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
72 template<class T, class U> constexpr bool operator!=(const T&, const optional<U>&);
73 template<class T, class U> constexpr bool operator<(const optional<T>&, const U&);
74 template<class T, class U> constexpr bool operator<(const T&, const optional<U>&);
75 template<class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
76 template<class T, class U> constexpr bool operator<=(const T&, const optional<U>&);
77 template<class T, class U> constexpr bool operator>(const optional<T>&, const U&);
78 template<class T, class U> constexpr bool operator>(const T&, const optional<U>&);
79 template<class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
80 template<class T, class U> constexpr bool operator>=(const T&, const optional<U>&);
82 requires (!is-derived-from-optional<U>) && three_way_comparable_with<T, U>
84 … operator<=>(const optional<T>&, const U&); // since C++20
86 // [optional.specalg], specialized algorithms
88 void swap(optional<T>&, optional<T>&) noexcept(see below ); // constexpr in C++20
91 constexpr optional<see below > make_optional(T&&);
93 constexpr optional<T> make_optional(Args&&... args);
95 constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
97 // [optional.hash], hash support
99 template<class T> struct hash<optional<T>>;
102 class optional {
106 // [optional.ctor], constructors
107 constexpr optional() noexcept;
108 constexpr optional(nullopt_t) noexcept;
109 constexpr optional(const optional &);
110 constexpr optional(optional &&) noexcept(see below);
112 constexpr explicit optional(in_place_t, Args &&...);
114 constexpr explicit optional(in_place_t, initializer_list<U>, Args &&...);
116 constexpr explicit(see-below) optional(U &&);
118 … explicit(see-below) optional(const optional<U> &); // constexpr in C++20
120 … explicit(see-below) optional(optional<U> &&); // constexpr in C++20
122 // [optional.dtor], destructor
123 ~optional(); // constexpr in C++20
125 // [optional.assign], assignment
126optional &operator=(nullopt_t) noexcept; // constexpr in C++20
127 constexpr optional &operator=(const optional &);
128 constexpr optional &operator=(optional &&) noexcept(see below);
129 …template<class U = T> optional &operator=(U &&); // constexpr in C++20
130 …template<class U> optional &operator=(const optional<U> &); // constexpr in C++20
131 …template<class U> optional &operator=(optional<U> &&); // constexpr in C++20
135 // [optional.swap], swap
136 void swap(optional &) noexcept(see below ); // constexpr in C++20
138 // [optional.observe], observers
154 // [optional.monadic], monadic operations
163 template<class F> constexpr optional or_else(F&& f) &&; // since C++23
164 template<class F> constexpr optional or_else(F&& f) const&; // since C++23
166 // [optional.mod], modifiers
174 optional(T) -> optional<T>;
229 // [optional.syn]
284 …static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefi…
320 …static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefi…
387 // optional<T&> is currently required to be ill-formed. However, it may
560 class optional;
565 concept __is_derived_from_optional = requires(const _Tp& __t) { []<class _Up>(const optional<_Up>&)…
572 struct __is_std_optional<optional<_Tp>> : true_type {};
575 class _LIBCPP_DECLSPEC_EMPTY_BASES optional
584 …ivially_relocatable = conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, optional, void>;
589 "instantiation of optional with in_place_t is ill-formed");
591 "instantiation of optional with nullopt_t is ill-formed");
592 …static_assert(!is_reference_v<value_type>, "instantiation of optional with a reference type is ill…
593 …static_assert(is_destructible_v<value_type>, "instantiation of optional with a non-destructible ty…
594 …static_assert(!is_array_v<value_type>, "instantiation of optional with an array type is ill-formed…
610 …<__remove_cvref_t<_Up>, in_place_t>::value && _IsNotSame<__remove_cvref_t<_Up>, optional>::value &&
616 template <class _Up, class _Opt = optional<_Up>>
626 template <class _Up, class _Opt = optional<_Up>>
662 _LIBCPP_HIDE_FROM_ABI constexpr optional() noexcept {}
663 _LIBCPP_HIDE_FROM_ABI constexpr optional(const optional&) = default;
664 _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&) = default;
665 _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {}
671 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args)
677 …_LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&.…
682 _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {}
685 …_LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) : __base(in_place, std::forward<_Up>(…
687 // LWG2756: conditionally explicit conversion from const optional<_Up>&
690 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) {
695 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) {
699 // LWG2756: conditionally explicit conversion from optional<_Up>&&
701 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) {
705 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) {
714 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Tag, _Fp&& __f, _Args&&... __args)
718 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(nullopt_t) noexcept {
723 _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(const optional&) = default;
724 _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(optional&&) = default;
729 class = enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Up>, optional>,
733 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(_Up&& __v) {
744 …_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(const optional<_Up>& __v) {
751 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(optional<_Up>&& __v) {
773 …swap(optional& __opt) noexcept(is_nothrow_move_constructible_v<value_type> && is_nothrow_swappable…
790 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator-> called on a disengaged…
795 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator-> called on a disengaged…
800 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
805 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
810 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
815 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
850 …static_assert(is_copy_constructible_v<value_type>, "optional<T>::value_or: T must be copy construc…
851 …static_assert(is_convertible_v<_Up, value_type>, "optional<T>::value_or: U must be convertible to …
857 …static_assert(is_move_constructible_v<value_type>, "optional<T>::value_or: T must be move construc…
858 …static_assert(is_convertible_v<_Up, value_type>, "optional<T>::value_or: U must be convertible to …
867 "Result of f(value()) must be a specialization of std::optional");
877 "Result of f(value()) must be a specialization of std::optional");
887 "Result of f(std::move(value())) must be a specialization of std::optional");
897 "Result of f(std::move(value())) must be a specialization of std::optional");
911 … return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), value());
912 return optional<_Up>();
923 … return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), value());
924 return optional<_Up>();
935 …return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), std::move(v…
936 return optional<_Up>();
947 …return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), std::move(v…
948 return optional<_Up>();
952 _LIBCPP_HIDE_FROM_ABI constexpr optional or_else(_Func&& __f) const&
955 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
956 "Result of f() should be the same type as this optional");
963 _LIBCPP_HIDE_FROM_ABI constexpr optional or_else(_Func&& __f) &&
966 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
967 "Result of f() should be the same type as this optional");
979 optional(_Tp) -> optional<_Tp>;
987 operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
999 operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1011 operator<(const optional<_Tp>& __x, const optional<_Up>& __y) {
1023 operator>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1035 operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1047 operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1059 operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1069 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept {
1076 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept {
1081 _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, nullopt_t) noexcept {
1086 _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(nullopt_t, const optional<_Tp>& __x) noexcept {
1091 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>&, nullopt_t) noexcept {
1096 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(nullopt_t, const optional<_Tp>& __x) noexcept {
1101 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, nullopt_t) noexcept {
1106 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(nullopt_t, const optional<_Tp>&) noexcept {
1111 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, nullopt_t) noexcept {
1116 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(nullopt_t, const optional<_Tp>&) noexcept {
1121 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>&, nullopt_t) noexcept {
1126 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(nullopt_t, const optional<_Tp>& __x) noexcept {
1133 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& __x, nullopt_t) no…
1144 operator==(const optional<_Tp>& __x, const _Up& __v) {
1152 operator==(const _Tp& __v, const optional<_Up>& __x) {
1160 operator!=(const optional<_Tp>& __x, const _Up& __v) {
1168 operator!=(const _Tp& __v, const optional<_Up>& __x) {
1176 operator<(const optional<_Tp>& __x, const _Up& __v) {
1184 operator<(const _Tp& __v, const optional<_Up>& __x) {
1192 operator<=(const optional<_Tp>& __x, const _Up& __v) {
1200 operator<=(const _Tp& __v, const optional<_Up>& __x) {
1208 operator>(const optional<_Tp>& __x, const _Up& __v) {
1216 operator>(const _Tp& __v, const optional<_Up>& __x) {
1224 operator>=(const optional<_Tp>& __x, const _Up& __v) {
1232 operator>=(const _Tp& __v, const optional<_Up>& __x) {
1241 operator<=>(const optional<_Tp>& __x, const _Up& __v) {
1250 swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) {
1255 _LIBCPP_HIDE_FROM_ABI constexpr optional<decay_t<_Tp>> make_optional(_Tp&& __v) {
1256 return optional<decay_t<_Tp>>(std::forward<_Tp>(__v));
1260 _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(_Args&&... __args) {
1261 return optional<_Tp>(in_place, std::forward<_Args>(__args)...);
1265 _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... …
1266 return optional<_Tp>(in_place, __il, std::forward<_Args>(__args)...);
1270 struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
1272 _LIBCPP_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type;
1276 _LIBCPP_HIDE_FROM_ABI size_t operator()(const optional<_Tp>& __opt) const {