• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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">&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        void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]``
200
201        // deprecated methods
202
203        // (deprecated)
204        void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]``
205
206        // (deprecated)
207        bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]``
208
209        // (deprecated)
210        T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]``
211    };
212
213
214[endsect]
215
216
217[section:header_optional_optional_refs Optional References]
218
219[#reference_operator_template_spec]
220    template <class T>
221    class optional<T&> // specilization for lvalue references
222    {
223    public :
224
225        typedef T& value_type;
226        typedef T& reference_type;
227        typedef T& reference_const_type; // no const propagation
228        typedef T& rval_reference_type;
229        typedef T* pointer_type;
230        typedef T* pointer_const_type;   // no const propagation
231
232        optional () noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
233
234        optional ( none_t ) noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
235
236        template<class R> optional(R&& r) noexcept ;  ``[link reference_optional_ref_value_ctor __GO_TO__]``
237
238        template <class R> optional(bool cond, R&& r) noexcept ; ``[link reference_optional_ref_cond_value_ctor __GO_TO__]``
239
240        optional ( optional const& rhs ) noexcept ; ``[link reference_optional_ref_copy_ctor __GO_TO__]``
241
242        template<class U> explicit optional ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_ctor_from_opt_U __GO_TO__]``
243
244        optional& operator = ( none_t ) noexcept ; ``[link reference_optional_ref_assign_none_t __GO_TO__]``
245
246        optional& operator = ( optional const& rhs ) noexcept; ``[link reference_optional_ref_copy_assign __GO_TO__]``
247
248        template<class U> optional& operator = ( optional<U&> const& rhs ) noexcept ; ``[link reference_optional_ref_assign_optional_U __GO_TO__]``
249
250        template<class R> optional& operator = (R&& r) noexcept ; ``[link reference_optional_ref_assign_R __GO_TO__]``
251
252        template<class R> void emplace ( R&& r ) noexcept ; ``[link reference_optional_ref_emplace_R __GO_TO__]``
253
254        T& get() const ; ``[link reference_optional_ref_get __GO_TO__]``
255        T& operator *() const ; ``[link reference_optional_ref_get __GO_TO__]``
256
257        T* operator ->() const ; ``[link reference_optional_ref_arrow __GO_TO__]``
258
259        T& value() const& ; ``[link reference_optional_ref_value __GO_TO__]``
260
261        template<class R> T& value_or( R && r ) const noexcept ; ``[link reference_optional_ref_value_or __GO_TO__]``
262
263        template<class F> T& value_or_eval( F f ) const ; ``[link reference_optional_ref_value_or_eval __GO_TO__]``
264
265        template<class F> auto map( F f ) const -> ``['see below]``; ``[link reference_optional_ref_map __GO_TO__]``
266
267        template<class F> auto flat_map( F f ) const -> ``['see below]``; ``[link reference_optional_ref_flat_map __GO_TO__]``
268
269        T* get_ptr() const noexcept ; ``[link reference_optional_ref_get_ptr __GO_TO__]``
270
271        bool has_value() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]``
272
273        explicit operator bool() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]``
274
275        bool operator!() const noexcept ; ``[link reference_optional_ref_operator_not __GO_TO__]``
276
277        void reset() noexcept ; ``[link reference_optional_ref_reset __GO_TO__]``
278
279        // deprecated methods
280
281        // (deprecated)
282        template<class R> void reset ( R && r ) noexcept ; ``[link reference_optional_ref_reset_value __GO_TO__]``
283
284        // (deprecated)
285        bool is_initialized() const noexcept ; ``[link reference_optional_ref_is_initialized __GO_TO__]``
286
287        // (deprecated)
288        template<class R> T& get_value_or( R && r ) constnoexcept; ``[link reference_optional_ref_get_value_or_value __GO_TO__]``
289
290    private:
291        T* ref; // exposition only
292    };
293[endsect]
294