]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
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">></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<T> make_optional ( bool condition, T const& v ) ; ``[link reference_make_optional_bool_value __GO_TO__]`` | |
49 | ||
50 | 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__]`` | |
51 | ||
52 | 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__]`` | |
53 | ||
54 | template<class T> inline T const& get ( optional<T> const& opt ) ; ``[link reference_optional_get __GO_TO__]`` | |
55 | ||
56 | template<class T> inline T& get ( optional<T> & opt ) ; ``[link reference_optional_get __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 auto get_pointer ( optional<T> const& opt ) -> ``['see below]``; ``[link reference_free_get_pointer __GO_TO__]`` | |
63 | ||
64 | template<class T> inline auto get_pointer ( optional<T> & opt ) -> ``['see below]``; ``[link reference_free_get_pointer __GO_TO__]`` | |
65 | ||
66 | template<class T> inline void swap( optional<T>& x, optional<T>& y ) ; ``[link reference_swap_optional_optional __GO_TO__]`` | |
67 | ||
68 | template<class T> inline void swap( optional<T&>& x, optional<T&>& y ) ; ``[link reference_swap_optional_reference __GO_TO__]`` | |
69 | ||
70 | } // namespace boost | |
71 | ||
72 | ||
73 | [endsect] | |
74 | ||
75 | ||
76 | [section:header_optional_in_place_init Initialization tags] | |
77 | ||
78 | [#reference_in_place_init] | |
79 | [#reference_in_place_init_if] | |
80 | ||
81 | namespace boost { | |
82 | ||
83 | class in_place_init_t { /* see below */ } ; | |
84 | const in_place_init_t in_place_init ( /* see below */ ) ; | |
85 | ||
86 | class in_place_init_if_t { /*see below*/ } ; | |
87 | const in_place_init_if_t in_place_init_if ( /*see below*/ ) ; | |
88 | ||
89 | } | |
90 | ||
91 | Classes `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. | |
92 | They are empty, trivially copyable classes with disabled default constructor. | |
93 | ||
94 | [endsect] | |
95 | ||
96 | [section:header_optional_optional_values Optional Values] | |
97 | ||
98 | [#reference_operator_template] | |
99 | ||
100 | template <class T> | |
101 | class optional | |
102 | { | |
103 | public : | |
104 | ||
105 | typedef T value_type ; | |
106 | typedef T & reference_type ; | |
107 | typedef T const& reference_const_type ; | |
108 | typedef T && rval_reference_type ; | |
109 | typedef T * pointer_type ; | |
110 | typedef T const* pointer_const_type ; | |
111 | ||
112 | optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]`` | |
113 | ||
114 | optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]`` | |
115 | ||
116 | optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]`` | |
117 | ||
118 | optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]`` | |
119 | ||
120 | optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]`` | |
121 | ||
122 | optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]`` | |
123 | ||
124 | optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]`` | |
125 | ||
126 | template<class U> explicit optional ( optional<U> const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]`` | |
127 | ||
128 | template<class U> explicit optional ( optional<U>&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]`` | |
129 | ||
130 | template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) ; ``[link reference_optional_in_place_init __GO_TO__]`` | |
131 | ||
132 | template<class... Args> explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; ``[link reference_optional_in_place_init_if __GO_TO__]`` | |
133 | ||
134 | template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` | |
135 | ||
136 | template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]`` | |
137 | ||
138 | optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]`` | |
139 | ||
140 | optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]`` | |
141 | ||
142 | optional& operator = ( T&& v ) ; ``[link reference_optional_operator_move_equal_value __GO_TO__]`` | |
143 | ||
144 | optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_optional __GO_TO__]`` | |
145 | ||
146 | optional& operator = ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_operator_move_equal_optional __GO_TO__]`` | |
147 | ||
148 | template<class U> optional& operator = ( optional<U> const& rhs ) ; ``[link reference_optional_operator_equal_other_optional __GO_TO__]`` | |
149 | ||
150 | template<class U> optional& operator = ( optional<U>&& rhs ) ; ``[link reference_optional_operator_move_equal_other_optional __GO_TO__]`` | |
151 | ||
152 | template<class... Args> void emplace ( Args&&... args ) ; ``[link reference_optional_emplace __GO_TO__]`` | |
153 | ||
154 | template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` | |
155 | ||
156 | template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]`` | |
157 | ||
158 | T const& get() const ; ``[link reference_optional_get __GO_TO__]`` | |
159 | T& get() ; ``[link reference_optional_get __GO_TO__]`` | |
160 | ||
161 | T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]`` | |
162 | T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]`` | |
163 | ||
164 | T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]`` | |
165 | T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]`` | |
166 | T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]`` | |
167 | ||
168 | T const& value() const& ; ``[link reference_optional_value __GO_TO__]`` | |
169 | T& value() & ; ``[link reference_optional_value __GO_TO__]`` | |
170 | T&& value() && ; ``[link reference_optional_value_move __GO_TO__]`` | |
171 | ||
172 | template<class U> T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]`` | |
173 | template<class U> T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]`` | |
174 | ||
175 | template<class F> T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]`` | |
176 | template<class F> T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]`` | |
177 | ||
178 | T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]`` | |
179 | T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]`` | |
180 | ||
181 | explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]`` | |
182 | ||
183 | bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]`` | |
184 | ||
185 | // deprecated methods | |
186 | ||
187 | // (deprecated) | |
188 | void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]`` | |
189 | ||
190 | // (deprecated) | |
191 | void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]`` | |
192 | ||
193 | // (deprecated) | |
194 | bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]`` | |
195 | ||
196 | // (deprecated) | |
197 | T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]`` | |
198 | }; | |
199 | ||
200 | ||
201 | [endsect] | |
202 | ||
203 | ||
204 | [section:header_optional_optional_refs Optional References] | |
205 | ||
206 | [#reference_operator_template_spec] | |
207 | template <class T> | |
208 | class optional<T&> // specilization for lvalue references | |
209 | { | |
210 | public : | |
211 | ||
212 | typedef T& value_type; | |
213 | typedef T& reference_type; | |
214 | typedef T& reference_const_type; // no const propagation | |
215 | typedef T& rval_reference_type; | |
216 | typedef T* pointer_type; | |
217 | typedef T* pointer_const_type; // no const propagation | |
218 | ||
219 | optional () noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]`` | |
220 | ||
221 | optional ( none_t ) noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]`` | |
222 | ||
223 | template<class R> optional(R&& r) noexcept ; ``[link reference_optional_ref_value_ctor __GO_TO__]`` | |
224 | ||
225 | template <class R> optional(bool cond, R&& r) noexcept ; ``[link reference_optional_ref_cond_value_ctor __GO_TO__]`` | |
226 | ||
227 | optional ( optional const& rhs ) noexcept ; ``[link reference_optional_ref_copy_ctor __GO_TO__]`` | |
228 | ||
229 | template<class U> explicit optional ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_ctor_from_opt_U __GO_TO__]`` | |
230 | ||
231 | optional& operator = ( none_t ) noexcept ; ``[link reference_optional_ref_assign_none_t __GO_TO__]`` | |
232 | ||
233 | ||
234 | optional& operator = ( optional const& rhs ) noexcept; ``[link reference_optional_ref_copy_assign __GO_TO__]`` | |
235 | ||
236 | template<class U> optional& operator = ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_assign_optional_U __GO_TO__]`` | |
237 | ||
238 | template<class R> optional& operator = (R&& r) noexcept ; ``[link reference_optional_ref_assign_R __GO_TO__]`` | |
239 | ||
240 | template<class R> void emplace ( R&& r ) noexcept ; ``[link reference_optional_ref_emplace_R __GO_TO__]`` | |
241 | ||
242 | T& get() const ; ``[link reference_optional_ref_get __GO_TO__]`` | |
243 | T& operator *() const ; ``[link reference_optional_ref_get __GO_TO__]`` | |
244 | ||
245 | T* operator ->() const ; ``[link reference_optional_ref_arrow __GO_TO__]`` | |
246 | ||
247 | T& value() const& ; ``[link reference_optional_ref_value __GO_TO__]`` | |
248 | ||
249 | template<class R> T& value_or( R && r ) const noexcept ; ``[link reference_optional_ref_value_or __GO_TO__]`` | |
250 | ||
251 | template<class F> T& value_or_eval( F f ) const ; ``[link reference_optional_ref_value_or_eval __GO_TO__]`` | |
252 | ||
253 | T* get_ptr() const noexcept ; ``[link reference_optional_ref_get_ptr __GO_TO__]`` | |
254 | ||
255 | explicit operator bool() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]`` | |
256 | ||
257 | bool operator!() const noexcept ; ``[link reference_optional_ref_operator_not __GO_TO__]`` | |
258 | ||
259 | // deprecated methods | |
260 | ||
261 | // (deprecated) | |
262 | void reset() noexcept ; ``[link reference_optional_ref_reset __GO_TO__]`` | |
263 | ||
264 | // (deprecated) | |
265 | template<class R> void reset ( R && r ) noexcept ; ``[link reference_optional_ref_reset_value __GO_TO__]`` | |
266 | ||
267 | // (deprecated) | |
268 | bool is_initialized() const noexcept ; ``[link reference_optional_ref_is_initialized __GO_TO__]`` | |
269 | ||
270 | // (deprecated) | |
271 | template<class R> T& get_value_or( R && r ) constnoexcept; ``[link reference_optional_ref_get_value_or_value __GO_TO__]`` | |
272 | ||
273 | private: | |
274 | T* ref; // exposition only | |
275 | }; | |
276 | [endsect] |