Skip to content

Commit 3df2337

Browse files
committed
make optional constexpr in C++14
1 parent bfdf0c7 commit 3df2337

28 files changed

+1397
-536
lines changed

doc/00_optional.qbk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[quickbook 1.4]
33
[authors [Cacciola Carballal, Fernando Luis]]
44
[copyright 2003-2007 Fernando Luis Cacciola Carballal]
5-
[copyright 2014-2024 Andrzej Krzemieński]
5+
[copyright 2014-2026 Andrzej Krzemieński]
66
[category miscellaneous]
77
[id optional]
88
[dirname optional]

doc/01_quick_start.qbk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ Suppose we want to implement a ['lazy load] optimization. This is because we do
124124

125125
`optional`'s default constructor creates an uninitialized optional. No call to `Resource`'s default constructor is attempted. `Resource` doesn't have to be __STD_DEFAULT_CONSTRUCTIBLE__. In function `getResource` we first check if `resource_` is initialized. This time we do not use the contextual conversion to `bool`, but a comparison with `boost::none`. These two ways are equivalent. Function `emplace` initializes the optional in-place by perfect-forwarding the arguments to the constructor of `Resource`. No copy- or move-construction is involved here. `Resource` doesn't even have to be `MoveConstructible`.
126126

127-
[note Function `emplace` is only available on compilers that support rvalue references and variadic templates. If your compiler does not support these features and you still need to avoid any move-constructions, use [link boost_optional.design.in_place_factories In-Place Factories].]
128127

129128
[endsect]
130129

doc/17_in_place_factories.qbk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,6 @@ In-place factories can be used generically by the wrapper and user as follows:
136136

137137
The factories are implemented in the headers: __IN_PLACE_FACTORY_HPP__ and __TYPED_IN_PLACE_FACTORY_HPP__
138138

139+
[caution The support for in-place factories is deprecated. Use constructor taking `in_place_init` tag and function `.emplace()` instead.]
140+
139141
[endsect]

doc/27_ref_optional_synopsis.qbk

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@
9595
namespace boost {
9696

9797
class in_place_init_t { /* see below */ } ;
98-
const in_place_init_t in_place_init ( /* see below */ ) ;
98+
inline constexpr in_place_init_t in_place_init ( /* see below */ ) ;
9999

100100
class in_place_init_if_t { /*see below*/ } ;
101-
const in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
101+
inline constexpr in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
102102

103103
}
104104

@@ -123,33 +123,33 @@ They are empty, trivially copyable classes with disabled default constructor.
123123
typedef T * pointer_type ;
124124
typedef T const* pointer_const_type ;
125125

126-
optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]``
126+
constexpr optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]``
127127

128-
optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]``
128+
constexpr optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]``
129129

130-
optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]``
130+
constexpr optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]``
131131

132-
optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]``
132+
constexpr optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]``
133133

134-
optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]``
134+
constexpr optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]``
135135

136-
optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]``
136+
constexpr optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]``
137137

138-
optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]``
138+
constexpr optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]``
139139

140-
template<class U> explicit optional ( optional<U> const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]``
140+
template<class U> constexpr explicit optional ( optional<U> const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]``
141141

142-
template<class U> explicit optional ( optional<U>&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]``
142+
template<class U> constexpr explicit optional ( optional<U>&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]``
143143

144-
template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) ; ``[link reference_optional_in_place_init __GO_TO__]``
144+
template<class... Args> constexpr explicit optional ( in_place_init_t, Args&&... args ) ; ``[link reference_optional_in_place_init __GO_TO__]``
145145

146-
template<class... Args> explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; ``[link reference_optional_in_place_init_if __GO_TO__]``
146+
template<class... Args> constexpr explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; ``[link reference_optional_in_place_init_if __GO_TO__]``
147147

148148
template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
149149

150150
template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
151151

152-
optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]``
152+
constexpr optional& operator = ( none_t ) noexcept ; ``[link reference_optional_operator_equal_none_t __GO_TO__]``
153153

154154
optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]``
155155

@@ -169,52 +169,50 @@ They are empty, trivially copyable classes with disabled default constructor.
169169

170170
template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]``
171171

172-
T const& get() const ; ``[link reference_optional_get __GO_TO__]``
173-
T& get() ; ``[link reference_optional_get __GO_TO__]``
172+
constexpr T const& get() const ; ``[link reference_optional_get __GO_TO__]``
173+
constexpr T& get() ; ``[link reference_optional_get __GO_TO__]``
174174

175-
T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]``
176-
T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]``
175+
constexpr T const* operator ->() const ; ``[link reference_optional_operator_arrow __GO_TO__]``
176+
constexpr T* operator ->() ; ``[link reference_optional_operator_arrow __GO_TO__]``
177177

178-
T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]``
179-
T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]``
180-
T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]``
178+
constexpr T const& operator *() const& ; ``[link reference_optional_operator_asterisk __GO_TO__]``
179+
constexpr T& operator *() & ; ``[link reference_optional_operator_asterisk __GO_TO__]``
180+
constexpr T&& operator *() && ; ``[link reference_optional_operator_asterisk_move __GO_TO__]``
181181

182-
T const& value() const& ; ``[link reference_optional_value __GO_TO__]``
183-
T& value() & ; ``[link reference_optional_value __GO_TO__]``
184-
T&& value() && ; ``[link reference_optional_value_move __GO_TO__]``
182+
constexpr T const& value() const& ; ``[link reference_optional_value __GO_TO__]``
183+
constexpr T& value() & ; ``[link reference_optional_value __GO_TO__]``
184+
constexpr T&& value() && ; ``[link reference_optional_value_move __GO_TO__]``
185185

186-
template<class U> T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]``
187-
template<class U> T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]``
186+
template<class U> constexpr T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]``
187+
template<class U> constexpr T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]``
188188

189-
template<class F> T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]``
190-
template<class F> T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]``
189+
template<class F> constexpr T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]``
190+
template<class F> constexpr T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]``
191191

192-
template<class F> auto map( F f ) const& -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
193-
template<class F> auto map( F f ) & -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
194-
template<class F> auto map( F f ) && -> ``['see below]``; ``[link reference_optional_map_move __GO_TO__]``
192+
template<class F> constexpr auto map( F f ) const& -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
193+
template<class F> constexpr auto map( F f ) & -> ``['see below]``; ``[link reference_optional_map __GO_TO__]``
194+
template<class F> constexpr auto map( F f ) && -> ``['see below]``; ``[link reference_optional_map_move __GO_TO__]``
195195

196-
template<class F> auto flat_map( F f ) const& -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
197-
template<class F> auto flat_map( F f ) & -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
198-
template<class F> auto flat_map( F f ) && -> ``['see below]``; ``[link reference_optional_flat_map_move __GO_TO__]``
196+
template<class F> constexpr auto flat_map( F f ) const& -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
197+
template<class F> constexpr auto flat_map( F f ) & -> ``['see below]``; ``[link reference_optional_flat_map __GO_TO__]``
198+
template<class F> constexpr auto flat_map( F f ) && -> ``['see below]``; ``[link reference_optional_flat_map_move __GO_TO__]``
199199

200200
T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]``
201201
T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]``
202202

203-
bool has_value() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
204-
205-
explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
203+
constexpr bool has_value() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
206204

207-
bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]``
205+
constexpr explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
208206

209-
void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]``
207+
constexpr void reset() noexcept ; ``[link reference_optional_reset __GO_TO__]``
210208

211209
// deprecated methods
212210

213211
// (deprecated)
214212
void reset ( T const& ) ; ``[link reference_optional_reset_value __GO_TO__]``
215213

216214
// (deprecated)
217-
bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]``
215+
constexpr bool is_initialized() const ; ``[link reference_optional_is_initialized __GO_TO__]``
218216

219217
// (deprecated)
220218
T const& get_value_or( T const& default ) const ; ``[link reference_optional_get_value_or_value __GO_TO__]``
@@ -239,9 +237,9 @@ They are empty, trivially copyable classes with disabled default constructor.
239237
typedef T* pointer_type;
240238
typedef T* pointer_const_type; // no const propagation
241239

242-
optional () noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
240+
constexpr optional () noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
243241

244-
optional ( none_t ) noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
242+
constexpr optional ( none_t ) noexcept ; ``[link reference_optional_ref_default_ctor __GO_TO__]``
245243

246244
template<class R> optional(R&& r) noexcept ; ``[link reference_optional_ref_value_ctor __GO_TO__]``
247245

0 commit comments

Comments
 (0)