Lines Matching refs: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
126 …optional &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>;
235 // [optional.syn]
290 …static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefi…
326 …static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefi…
393 // optional<T&> is currently required to be ill-formed. However, it may
566 class optional;
571 concept __is_derived_from_optional = requires(const _Tp& __t) { []<class _Up>(const optional<_Up>&)…
578 struct __is_std_optional<optional<_Tp>> : true_type {};
581 class _LIBCPP_DECLSPEC_EMPTY_BASES optional
593 "instantiation of optional with in_place_t is ill-formed");
595 "instantiation of optional with nullopt_t is ill-formed");
596 …static_assert(!is_reference_v<value_type>, "instantiation of optional with a reference type is ill…
597 …static_assert(is_destructible_v<value_type>, "instantiation of optional with a non-destructible ty…
598 …static_assert(!is_array_v<value_type>, "instantiation of optional with an array type is ill-formed…
614 …<__remove_cvref_t<_Up>, in_place_t>::value && _IsNotSame<__remove_cvref_t<_Up>, optional>::value &&
620 template <class _Up, class _Opt = optional<_Up>>
630 template <class _Up, class _Opt = optional<_Up>>
666 _LIBCPP_HIDE_FROM_ABI constexpr optional() noexcept {}
667 _LIBCPP_HIDE_FROM_ABI constexpr optional(const optional&) = default;
668 _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&) = default;
669 _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {}
675 _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args)
681 …_LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&.…
686 _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {}
689 …_LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) : __base(in_place, std::forward<_Up>(…
691 // LWG2756: conditionally explicit conversion from const optional<_Up>&
694 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) {
699 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) {
703 // LWG2756: conditionally explicit conversion from optional<_Up>&&
705 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) {
709 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) {
715 …_LIBCPP_HIDE_FROM_ABI constexpr explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f,…
719 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(nullopt_t) noexcept {
724 _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(const optional&) = default;
725 _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(optional&&) = default;
730 class = enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Up>, optional>,
734 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(_Up&& __v) {
745 …_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(const optional<_Up>& __v) {
752 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(optional<_Up>&& __v) {
774 …swap(optional& __opt) noexcept(is_nothrow_move_constructible_v<value_type> && is_nothrow_swappable…
791 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator-> called on a disengaged…
796 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator-> called on a disengaged…
801 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
806 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
811 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
816 …_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(this->has_value(), "optional operator* called on a disengaged …
851 …static_assert(is_copy_constructible_v<value_type>, "optional<T>::value_or: T must be copy construc…
852 …static_assert(is_convertible_v<_Up, value_type>, "optional<T>::value_or: U must be convertible to …
858 …static_assert(is_move_constructible_v<value_type>, "optional<T>::value_or: T must be move construc…
859 …static_assert(is_convertible_v<_Up, value_type>, "optional<T>::value_or: U must be convertible to …
868 "Result of f(value()) must be a specialization of std::optional");
878 "Result of f(value()) must be a specialization of std::optional");
888 "Result of f(std::move(value())) must be a specialization of std::optional");
898 "Result of f(std::move(value())) must be a specialization of std::optional");
912 … return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), value());
913 return optional<_Up>();
924 … return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), value());
925 return optional<_Up>();
936 …return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), std::move(v…
937 return optional<_Up>();
948 …return optional<_Up>(__optional_construct_from_invoke_tag{}, std::forward<_Func>(__f), std::move(v…
949 return optional<_Up>();
953 _LIBCPP_HIDE_FROM_ABI constexpr optional or_else(_Func&& __f) const&
956 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
957 "Result of f() should be the same type as this optional");
964 _LIBCPP_HIDE_FROM_ABI constexpr optional or_else(_Func&& __f) &&
967 static_assert(is_same_v<remove_cvref_t<invoke_result_t<_Func>>, optional>,
968 "Result of f() should be the same type as this optional");
980 optional(_Tp) -> optional<_Tp>;
988 operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
1000 operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1012 operator<(const optional<_Tp>& __x, const optional<_Up>& __y) {
1024 operator>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1036 operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1048 operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1060 operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1070 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept {
1077 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept {
1082 _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, nullopt_t) noexcept {
1087 _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(nullopt_t, const optional<_Tp>& __x) noexcept {
1092 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>&, nullopt_t) noexcept {
1097 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(nullopt_t, const optional<_Tp>& __x) noexcept {
1102 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, nullopt_t) noexcept {
1107 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(nullopt_t, const optional<_Tp>&) noexcept {
1112 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, nullopt_t) noexcept {
1117 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(nullopt_t, const optional<_Tp>&) noexcept {
1122 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>&, nullopt_t) noexcept {
1127 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(nullopt_t, const optional<_Tp>& __x) noexcept {
1134 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& __x, nullopt_t) no…
1145 operator==(const optional<_Tp>& __x, const _Up& __v) {
1153 operator==(const _Tp& __v, const optional<_Up>& __x) {
1161 operator!=(const optional<_Tp>& __x, const _Up& __v) {
1169 operator!=(const _Tp& __v, const optional<_Up>& __x) {
1177 operator<(const optional<_Tp>& __x, const _Up& __v) {
1185 operator<(const _Tp& __v, const optional<_Up>& __x) {
1193 operator<=(const optional<_Tp>& __x, const _Up& __v) {
1201 operator<=(const _Tp& __v, const optional<_Up>& __x) {
1209 operator>(const optional<_Tp>& __x, const _Up& __v) {
1217 operator>(const _Tp& __v, const optional<_Up>& __x) {
1225 operator>=(const optional<_Tp>& __x, const _Up& __v) {
1233 operator>=(const _Tp& __v, const optional<_Up>& __x) {
1242 operator<=>(const optional<_Tp>& __x, const _Up& __v) {
1251 swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) {
1256 _LIBCPP_HIDE_FROM_ABI constexpr optional<decay_t<_Tp>> make_optional(_Tp&& __v) {
1257 return optional<decay_t<_Tp>>(std::forward<_Tp>(__v));
1261 _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(_Args&&... __args) {
1262 return optional<_Tp>(in_place, std::forward<_Args>(__args)...);
1266 _LIBCPP_HIDE_FROM_ABI constexpr optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... …
1267 return optional<_Tp>(in_place, __il, std::forward<_Args>(__args)...);
1271 struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
1273 _LIBCPP_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type;
1277 _LIBCPP_HIDE_FROM_ABI size_t operator()(const optional<_Tp>& __opt) const {