|
13 | 13 |
|
14 | 14 |
|
15 | 15 | [section Minimum System Requirements] |
16 | | -This library requires C++11 as minimum. However some features are disabled. |
| 16 | +This library requires C++11 as minimum. However, in C++11 some features are disabled. |
17 | 17 |
|
18 | | -For C++14 and higher this library provides a `constexpr` interface for non-mutable |
19 | | -member functions and some mutable member functions. |
| 18 | +[section:constexpr Support for `constexpr`] |
| 19 | + |
| 20 | +[section C++11] |
| 21 | +For compilers fully supporting C++11 (including unconstrained unions and ref-qualifiers), |
| 22 | +for trivially-destructible `T`s, `optional<T>` is a ['literal type] and its constructors |
| 23 | +with `this->has_value() == false` as postcondition: |
| 24 | + |
| 25 | +* `optional()`, |
| 26 | +* `optional(none_t)`, |
| 27 | + |
| 28 | +are ['core constant expressions]. Even for other `T`s, these constructors are guaranteed to |
| 29 | +perform ['constant initialization]: they are never subject to "initialization order fiasco". |
| 30 | + |
| 31 | +Other constructors with `this->has_value() == true` |
| 32 | +as postcondition are core constant expressions if the expression required to initialize |
| 33 | +the contained value is a core constant expression. This includes constructors: |
| 34 | + |
| 35 | +* `template <typename... Args> optional(in_place_init, Args&&...)`, |
| 36 | +* `template <typename U> optional(U&&)`, |
| 37 | +* `optional(const T&)`, |
| 38 | +* `optional(T&&)`. |
| 39 | + |
| 40 | +Other constructors, including the copy and move constructos, are ['not] core constant expressions. |
| 41 | + |
| 42 | +Member functions `.has_value`, `operator bool` and (non)equality comparisons with `none` are core-constant expressions for trivially-destructible `T`s. |
| 43 | + |
| 44 | +Also all `const`-qualified non-static member functions and comparison operators are core constant expressions, if the corresponding operations on `T` |
| 45 | +are core constant expressions. |
| 46 | +[endsect] |
| 47 | + |
| 48 | +[section C++14] |
| 49 | +For C++14 and higher this library, for trivially-destructible `T`s provides the `constexpr` interface for all mutable and non-mutable |
| 50 | +member functions, as long as: |
| 51 | + |
| 52 | +* the corresponding operations on `T` are core constant expressions and |
| 53 | +* the member never attempts to change the `optional`'s state from not containing a value to containing a value. |
20 | 54 |
|
21 | 55 | [note For types that overload unary `operator&` (address) some member functions in `optional`, like `operator->`, |
22 | 56 | cannot be implemented as `constexpr` on some compilers.] |
| 57 | +[endsect] |
| 58 | + |
| 59 | +[section C++17] |
| 60 | +In C++17 all non-deprecated constructors are core constant expressions as long as |
| 61 | +`T` is a literal type and its constructor used is a core constant expression. |
| 62 | +[endsect] |
| 63 | + |
| 64 | +[endsect:constexpr] |
23 | 65 |
|
24 | 66 | [endsect] |
25 | 67 |
|
|
0 commit comments