blob: 7114b43350844725878f966fa37b56b0d63100bb [file] [log] [blame]
Brian Silvermanaf2eaa82018-08-04 17:28:31 -07001[/
2 Boost.Optional
3
4 Copyright (c) 2003-2007 Fernando Luis Cacciola Carballal
5
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9]
10
11
12[#ref_header_optional_optional_hpp] [section:header_optional_optional Synopsis]
13
14 ```// In Header: <`[@boost:/boost/optional/optional.hpp boost/optional/optional.hpp]'''<phrase role="comment">&gt;</phrase>'''``
15
16 namespace boost {
17
18 class in_place_init_t { /* see below */ } ; ``[link reference_in_place_init __GO_TO__]``
19 const in_place_init_t in_place_init ( /* see below */ ) ;
20
21 class in_place_init_if_t { /*see below*/ } ; ``[link reference_in_place_init_if __GO_TO__]``
22 const in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
23
24 template <class T>
25 class optional ; ``[link reference_operator_template __GO_TO__]``
26
27 template <class T>
28 class optional<T&> ; ``[link reference_operator_template_spec __GO_TO__]``
29
30 template<class T> inline bool operator == ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_equal_optional_optional __GO_TO__]``
31
32 template<class T> inline bool operator != ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_not_equal_optional_optional __GO_TO__]``
33
34 template<class T> inline bool operator < ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_less_optional_optional __GO_TO__]``
35
36 template<class T> inline bool operator > ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_greater_optional_optional __GO_TO__]``
37
38 template<class T> inline bool operator <= ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_less_or_equal_optional_optional __GO_TO__]``
39
40 template<class T> inline bool operator >= ( optional<T> const& x, optional<T> const& y ) ; ``[link reference_operator_compare_greater_or_equal_optional_optional __GO_TO__]``
41
42 template<class T> inline bool operator == ( optional<T> const& x, none_t ) noexcept ; ``[link reference_operator_compare_equal_optional_none __GO_TO__]``
43
44 template<class T> inline bool operator != ( optional<T> const& x, none_t ) noexcept ; ``[link reference_operator_compare_not_equal_optional_none __GO_TO__]``
45
46 template<class T> inline optional<T> make_optional ( T const& v ) ; ``[link reference_make_optional_value __GO_TO__]``
47
48 template<class T> inline optional<std::decay_t<T>> make_optional ( T && v ) ; ``[link reference_make_optional_rvalue __GO_TO__]``
49
50 template<class T> inline optional<T> make_optional ( bool condition, T const& v ) ; ``[link reference_make_optional_bool_value __GO_TO__]``
51
52 template<class T> inline optional<std::decay_t<T>> make_optional ( bool condition, T && v ) ; ``[link reference_make_optional_bool_rvalue __GO_TO__]``
53
54 template<class T> inline auto get_optional_value_or ( optional<T> const& opt, typename optional<T>::reference_const_type def ) -> typename optional<T>::reference_const_type; ``[link reference_free_get_value_or __GO_TO__]``
55
56 template<class T> inline auto get_optional_value_or ( optional<T> const& opt, typename optional<T>::reference_type def ) -> typename optional<T>::reference_type ; ``[link reference_free_get_value_or __GO_TO__]``
57
58 template<class T> inline T const& get ( optional<T> const& opt ) ; ``[link reference_optional_get __GO_TO__]``
59
60 template<class T> inline T& get ( optional<T> & opt ) ; ``[link reference_optional_get __GO_TO__]``
61
62 template<class T> inline T const* get ( optional<T> const* opt ) ; ``[link reference_optional_get __GO_TO__]``
63
64 template<class T> inline T* get ( optional<T>* opt ) ; ``[link reference_optional_get __GO_TO__]``
65
66 template<class T> inline auto get_pointer ( optional<T> const& opt ) -> ``['see below]``; ``[link reference_free_get_pointer __GO_TO__]``
67
68 template<class T> inline auto get_pointer ( optional<T> & opt ) -> ``['see below]``; ``[link reference_free_get_pointer __GO_TO__]``
69
70 template<class T> inline void swap( optional<T>& x, optional<T>& y ) ; ``[link reference_swap_optional_optional __GO_TO__]``
71
72 template<class T> inline void swap( optional<T&>& x, optional<T&>& y ) ; ``[link reference_swap_optional_reference __GO_TO__]``
73
74 } // namespace boost
75
76
77[endsect]
78
79
80[section:header_optional_in_place_init Initialization tags]
81
82[#reference_in_place_init]
83[#reference_in_place_init_if]
84
85 namespace boost {
86
87 class in_place_init_t { /* see below */ } ;
88 const in_place_init_t in_place_init ( /* see below */ ) ;
89
90 class in_place_init_if_t { /*see below*/ } ;
91 const in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
92
93 }
94
95Classes `in_place_init_t` and `in_place_init_if_t` are empty clsses. Their purpose is to control overload resolution in the initialization of optional objects.
96They are empty, trivially copyable classes with disabled default constructor.
97
98[endsect]
99
100[section:header_optional_optional_values Optional Values]
101
102[#reference_operator_template]
103
104 template <class T>
105 class optional
106 {
107 public :
108
109 typedef T value_type ;
110 typedef T & reference_type ;
111 typedef T const& reference_const_type ;
112 typedef T && rval_reference_type ;
113 typedef T * pointer_type ;
114 typedef T const* pointer_const_type ;
115
116 optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]``
117
118 optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]``
119
120 optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]``
121
122 optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]``
123
124 optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]``
125
126 optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]``
127
128 optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]``
129
130 template<class U> explicit optional ( optional<U> const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]``
131
132 template<class U> explicit optional ( optional<U>&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]``
133
134 template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) ; ``[link reference_optional_in_place_init __GO_TO__]``
135
136 template<class... Args> explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; ``[link reference_optional_in_place_init_if __GO_TO__]``
137
138 template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
139
140 template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
141
142 optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]``
143
144 optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]``
145
146 optional& operator = ( T&& v ) ; ``[link reference_optional_operator_move_equal_value __GO_TO__]``
147
148 optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_optional __GO_TO__]``
149
150 optional& operator = ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_operator_move_equal_optional __GO_TO__]``
151
152 template<class U> optional& operator = ( optional<U> const& rhs ) ; ``[link reference_optional_operator_equal_other_optional __GO_TO__]``
153
154 template<class U> optional& operator = ( optional<U>&& rhs ) ; ``[link reference_optional_operator_move_equal_other_optional __GO_TO__]``
155
156 template<class... Args> void emplace ( Args&&... args ) ; ``[link reference_optional_emplace __GO_TO__]``
157
158 template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]``
159
160 template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]``
161
162 T const& get() const ; ``[link reference_optional_get __GO_TO__]``
163 T& get() ; ``[link reference_optional_get __GO_TO__]``
164
165 T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]``
166 T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]``
167
168 T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]``
169 T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]``
170 T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]``
171
172 T const& value() const& ; ``[link reference_optional_value __GO_TO__]``
173 T& value() & ; ``[link reference_optional_value __GO_TO__]``
174 T&& value() && ; ``[link reference_optional_value_move __GO_TO__]``
175
176 template<class U> T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]``
177 template<class U> T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]``
178
179 template<class F> T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]``
180 template<class F> T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]``
181
182 template<class F> auto map( F f ) const& -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
183 template<class F> auto map( F f ) & -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
184 template<class F> auto map( F f ) && -> ``['see below]``; ``[link reference_optional_map_move __GO_TO__]``
185
186 template<class F> auto flat_map( F f ) const& -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
187 template<class F> auto flat_map( F f ) & -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
188 template<class F> auto flat_map( F f ) && -> ``['see below]``; ``[link reference_optional_flat_map_move __GO_TO__]``
189
190 T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]``
191 T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]``
192
193 bool has_value() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
194
195 explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
196
197 bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]``
198
199 // deprecated methods
200
201 // (deprecated)
202 void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]``
203
204 // (deprecated)
205 void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]``
206
207 // (deprecated)
208 bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]``
209
210 // (deprecated)
211 T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]``
212 };
213
214
215[endsect]
216
217
218[section:header_optional_optional_refs Optional References]
219
220[#reference_operator_template_spec]
221 template <class T>
222 class optional<T&> // specilization for lvalue references
223 {
224 public :
225
226 typedef T& value_type;
227 typedef T& reference_type;
228 typedef T& reference_const_type; // no const propagation
229 typedef T& rval_reference_type;
230 typedef T* pointer_type;
231 typedef T* pointer_const_type; // no const propagation
232
233 optional () noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
234
235 optional ( none_t ) noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
236
237 template<class R> optional(R&& r) noexcept ; ``[link reference_optional_ref_value_ctor __GO_TO__]``
238
239 template <class R> optional(bool cond, R&& r) noexcept ; ``[link reference_optional_ref_cond_value_ctor __GO_TO__]``
240
241 optional ( optional const& rhs ) noexcept ; ``[link reference_optional_ref_copy_ctor __GO_TO__]``
242
243 template<class U> explicit optional ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_ctor_from_opt_U __GO_TO__]``
244
245 optional& operator = ( none_t ) noexcept ; ``[link reference_optional_ref_assign_none_t __GO_TO__]``
246
247 optional& operator = ( optional const& rhs ) noexcept; ``[link reference_optional_ref_copy_assign __GO_TO__]``
248
249 template<class U> optional& operator = ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_assign_optional_U __GO_TO__]``
250
251 template<class R> optional& operator = (R&& r) noexcept ; ``[link reference_optional_ref_assign_R __GO_TO__]``
252
253 template<class R> void emplace ( R&& r ) noexcept ; ``[link reference_optional_ref_emplace_R __GO_TO__]``
254
255 T& get() const ; ``[link reference_optional_ref_get __GO_TO__]``
256 T& operator *() const ; ``[link reference_optional_ref_get __GO_TO__]``
257
258 T* operator ->() const ; ``[link reference_optional_ref_arrow __GO_TO__]``
259
260 T& value() const& ; ``[link reference_optional_ref_value __GO_TO__]``
261
262 template<class R> T& value_or( R && r ) const noexcept ; ``[link reference_optional_ref_value_or __GO_TO__]``
263
264 template<class F> T& value_or_eval( F f ) const ; ``[link reference_optional_ref_value_or_eval __GO_TO__]``
265
266 template<class F> auto map( F f ) const -> ``['see below]``; ``[link reference_optional_ref_map __GO_TO__]``
267
268 template<class F> auto flat_map( F f ) const -> ``['see below]``; ``[link reference_optional_ref_flat_map __GO_TO__]``
269
270 T* get_ptr() const noexcept ; ``[link reference_optional_ref_get_ptr __GO_TO__]``
271
272 bool has_value() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]``
273
274 explicit operator bool() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]``
275
276 bool operator!() const noexcept ; ``[link reference_optional_ref_operator_not __GO_TO__]``
277
278 // deprecated methods
279
280 // (deprecated)
281 void reset() noexcept ; ``[link reference_optional_ref_reset __GO_TO__]``
282
283 // (deprecated)
284 template<class R> void reset ( R && r ) noexcept ; ``[link reference_optional_ref_reset_value __GO_TO__]``
285
286 // (deprecated)
287 bool is_initialized() const noexcept ; ``[link reference_optional_ref_is_initialized __GO_TO__]``
288
289 // (deprecated)
290 template<class R> T& get_value_or( R && r ) constnoexcept; ``[link reference_optional_ref_get_value_or_value __GO_TO__]``
291
292 private:
293 T* ref; // exposition only
294 };
295[endsect]