- tmp/tmpy4ltest6/{from.md → to.md} +76 -102
tmp/tmpy4ltest6/{from.md → to.md}
RENAMED
|
@@ -1,210 +1,184 @@
|
|
| 1 |
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 2 |
|
| 3 |
In the descriptions that follow, let i be in the range \[`0`,
|
| 4 |
-
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types
|
| 5 |
|
| 6 |
``` cpp
|
| 7 |
constexpr variant() noexcept(see below);
|
| 8 |
```
|
| 9 |
|
|
|
|
|
|
|
| 10 |
*Effects:* Constructs a `variant` holding a value-initialized value of
|
| 11 |
type `T₀`.
|
| 12 |
|
| 13 |
-
*
|
| 14 |
-
`0`.
|
| 15 |
|
| 16 |
*Throws:* Any exception thrown by the value-initialization of `T₀`.
|
| 17 |
|
| 18 |
-
*Remarks:* This function
|
| 19 |
value-initialization of the alternative type `T₀` would satisfy the
|
| 20 |
requirements for a constexpr function. The expression inside `noexcept`
|
| 21 |
-
is equivalent to `is_nothrow_default_constructible_v<``T₀``>`.
|
| 22 |
-
function shall not participate in overload resolution unless
|
| 23 |
-
`is_default_constructible_v<``T₀``>` is `true`.
|
| 24 |
|
| 25 |
[*Note 1*: See also class `monostate`. — *end note*]
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
-
variant(const variant& w);
|
| 29 |
```
|
| 30 |
|
| 31 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 32 |
same alternative as `w` and direct-initializes the contained value with
|
| 33 |
`get<j>(w)`, where `j` is `w.index()`. Otherwise, initializes the
|
| 34 |
`variant` to not hold a value.
|
| 35 |
|
| 36 |
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 37 |
i.
|
| 38 |
|
| 39 |
-
*Remarks:* This
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
``` cpp
|
| 43 |
-
variant(variant&& w) noexcept(see below);
|
| 44 |
```
|
| 45 |
|
|
|
|
|
|
|
| 46 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 47 |
same alternative as `w` and direct-initializes the contained value with
|
| 48 |
`get<j>(std::move(w))`, where `j` is `w.index()`. Otherwise, initializes
|
| 49 |
the `variant` to not hold a value.
|
| 50 |
|
| 51 |
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 52 |
|
| 53 |
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
``` cpp
|
| 59 |
template<class T> constexpr variant(T&& t) noexcept(see below);
|
| 60 |
```
|
| 61 |
|
| 62 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 63 |
-
function *FUN*(Tᵢ) for each alternative type `Tᵢ`
|
| 64 |
-
|
| 65 |
-
*FUN*(
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
*Effects:* Initializes `*this` to hold the alternative type `Tⱼ` and
|
| 69 |
direct-initializes the contained value as if
|
| 70 |
direct-non-list-initializing it with `std::forward<T>(t)`.
|
| 71 |
|
| 72 |
-
*
|
| 73 |
|
| 74 |
*Throws:* Any exception thrown by the initialization of the selected
|
| 75 |
alternative `Tⱼ`.
|
| 76 |
|
| 77 |
-
*Remarks:*
|
| 78 |
-
unless `is_same_v<decay_t<T>, variant>` is `false`, unless `decay_t<T>`
|
| 79 |
-
is neither a specialization of `in_place_type_t` nor a specialization of
|
| 80 |
-
`in_place_index_t`, unless `is_constructible_v<``Tⱼ``, T>` is `true`,
|
| 81 |
-
and unless the expression *FUN*(`std::forward<T>(t))` (with *FUN* being
|
| 82 |
-
the above-mentioned set of imaginary functions) is well formed.
|
| 83 |
-
|
| 84 |
-
[*Note 2*:
|
| 85 |
-
|
| 86 |
-
``` cpp
|
| 87 |
-
variant<string, string> v("abc");
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
is ill-formed, as both alternative types have an equally viable
|
| 91 |
-
constructor for the argument.
|
| 92 |
-
|
| 93 |
-
— *end note*]
|
| 94 |
-
|
| 95 |
-
The expression inside `noexcept` is equivalent to
|
| 96 |
`is_nothrow_constructible_v<``Tⱼ``, T>`. If `Tⱼ`’s selected constructor
|
| 97 |
-
is a constexpr constructor, this constructor
|
| 98 |
-
constructor.
|
| 99 |
|
| 100 |
``` cpp
|
| 101 |
template<class T, class... Args> constexpr explicit variant(in_place_type_t<T>, Args&&... args);
|
| 102 |
```
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
*Effects:* Initializes the contained value as if
|
| 105 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 106 |
`std::forward<Args>(args)...`.
|
| 107 |
|
| 108 |
-
*
|
| 109 |
|
| 110 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 111 |
`T`.
|
| 112 |
|
| 113 |
-
*Remarks:*
|
| 114 |
-
|
| 115 |
-
`is_constructible_v<T, Args...>` is `true`. If `T`’s selected
|
| 116 |
-
constructor is a constexpr constructor, this constructor shall be a
|
| 117 |
-
constexpr constructor.
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
template<class T, class U, class... Args>
|
| 121 |
constexpr explicit variant(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 122 |
```
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
*Effects:* Initializes the contained value as if
|
| 125 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 126 |
`il, std::forward<Args>(args)...`.
|
| 127 |
|
| 128 |
-
*
|
| 129 |
|
| 130 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 131 |
`T`.
|
| 132 |
|
| 133 |
-
*Remarks:*
|
| 134 |
-
|
| 135 |
-
`is_constructible_v<T, initializer_list<U>&, Args...>` is `true`. If
|
| 136 |
-
`T`’s selected constructor is a constexpr constructor, this constructor
|
| 137 |
-
shall be a constexpr constructor.
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
template<size_t I, class... Args> constexpr explicit variant(in_place_index_t<I>, Args&&... args);
|
| 141 |
```
|
| 142 |
|
| 143 |
-
*
|
| 144 |
-
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 145 |
-
`std::forward<Args>(args)...`.
|
| 146 |
-
|
| 147 |
-
*Postconditions:* `index()` is `I`.
|
| 148 |
-
|
| 149 |
-
*Throws:* Any exception thrown by calling the selected constructor of
|
| 150 |
-
`T_I`.
|
| 151 |
-
|
| 152 |
-
*Remarks:* This function shall not participate in overload resolution
|
| 153 |
-
unless
|
| 154 |
|
| 155 |
- `I` is less than `sizeof...(Types)` and
|
| 156 |
- `is_constructible_v<``T_I``, Args...>` is `true`.
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
``` cpp
|
| 162 |
template<size_t I, class U, class... Args>
|
| 163 |
constexpr explicit variant(in_place_index_t<I>, initializer_list<U> il, Args&&... args);
|
| 164 |
```
|
| 165 |
|
| 166 |
-
*
|
| 167 |
-
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 168 |
-
`il, std::forward<Args>(args)...`.
|
| 169 |
-
|
| 170 |
-
*Postconditions:* `index()` is `I`.
|
| 171 |
-
|
| 172 |
-
*Remarks:* This function shall not participate in overload resolution
|
| 173 |
-
unless
|
| 174 |
|
| 175 |
- `I` is less than `sizeof...(Types)` and
|
| 176 |
- `is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is
|
| 177 |
`true`.
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
-
``
|
| 183 |
-
// allocator-extended constructors
|
| 184 |
-
template <class Alloc>
|
| 185 |
-
variant(allocator_arg_t, const Alloc& a);
|
| 186 |
-
template <class Alloc>
|
| 187 |
-
variant(allocator_arg_t, const Alloc& a, const variant& v);
|
| 188 |
-
template <class Alloc>
|
| 189 |
-
variant(allocator_arg_t, const Alloc& a, variant&& v);
|
| 190 |
-
template <class Alloc, class T>
|
| 191 |
-
variant(allocator_arg_t, const Alloc& a, T&& t);
|
| 192 |
-
template <class Alloc, class T, class... Args>
|
| 193 |
-
variant(allocator_arg_t, const Alloc& a, in_place_type_t<T>, Args&&... args);
|
| 194 |
-
template <class Alloc, class T, class U, class... Args>
|
| 195 |
-
variant(allocator_arg_t, const Alloc& a, in_place_type_t<T>,
|
| 196 |
-
initializer_list<U> il, Args&&... args);
|
| 197 |
-
template <class Alloc, size_t I, class... Args>
|
| 198 |
-
variant(allocator_arg_t, const Alloc& a, in_place_index_t<I>, Args&&... args);
|
| 199 |
-
template <class Alloc, size_t I, class U, class... Args>
|
| 200 |
-
variant(allocator_arg_t, const Alloc& a, in_place_index_t<I>,
|
| 201 |
-
initializer_list<U> il, Args&&... args);
|
| 202 |
-
```
|
| 203 |
|
| 204 |
-
*
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
*Effects:* Equivalent to the preceding constructors except that the
|
| 208 |
-
contained value is constructed with uses-allocator
|
| 209 |
-
construction ([[allocator.uses.construction]]).
|
| 210 |
|
|
|
|
| 1 |
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 2 |
|
| 3 |
In the descriptions that follow, let i be in the range \[`0`,
|
| 4 |
+
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types`.
|
| 5 |
|
| 6 |
``` cpp
|
| 7 |
constexpr variant() noexcept(see below);
|
| 8 |
```
|
| 9 |
|
| 10 |
+
*Constraints:* `is_default_constructible_v<``T₀``>` is `true`.
|
| 11 |
+
|
| 12 |
*Effects:* Constructs a `variant` holding a value-initialized value of
|
| 13 |
type `T₀`.
|
| 14 |
|
| 15 |
+
*Ensures:* `valueless_by_exception()` is `false` and `index()` is `0`.
|
|
|
|
| 16 |
|
| 17 |
*Throws:* Any exception thrown by the value-initialization of `T₀`.
|
| 18 |
|
| 19 |
+
*Remarks:* This function is `constexpr` if and only if the
|
| 20 |
value-initialization of the alternative type `T₀` would satisfy the
|
| 21 |
requirements for a constexpr function. The expression inside `noexcept`
|
| 22 |
+
is equivalent to `is_nothrow_default_constructible_v<``T₀``>`.
|
|
|
|
|
|
|
| 23 |
|
| 24 |
[*Note 1*: See also class `monostate`. — *end note*]
|
| 25 |
|
| 26 |
``` cpp
|
| 27 |
+
constexpr variant(const variant& w);
|
| 28 |
```
|
| 29 |
|
| 30 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 31 |
same alternative as `w` and direct-initializes the contained value with
|
| 32 |
`get<j>(w)`, where `j` is `w.index()`. Otherwise, initializes the
|
| 33 |
`variant` to not hold a value.
|
| 34 |
|
| 35 |
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 36 |
i.
|
| 37 |
|
| 38 |
+
*Remarks:* This constructor is defined as deleted unless
|
| 39 |
+
`is_copy_constructible_v<``Tᵢ``>` is `true` for all i. If
|
| 40 |
+
`is_trivially_copy_constructible_v<``Tᵢ``>` is `true` for all i, this
|
| 41 |
+
constructor is trivial.
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
+
constexpr variant(variant&& w) noexcept(see below);
|
| 45 |
```
|
| 46 |
|
| 47 |
+
*Constraints:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 48 |
+
|
| 49 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 50 |
same alternative as `w` and direct-initializes the contained value with
|
| 51 |
`get<j>(std::move(w))`, where `j` is `w.index()`. Otherwise, initializes
|
| 52 |
the `variant` to not hold a value.
|
| 53 |
|
| 54 |
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 55 |
|
| 56 |
*Remarks:* The expression inside `noexcept` is equivalent to the logical
|
| 57 |
+
of `is_nothrow_move_constructible_v<``Tᵢ``>` for all i. If
|
| 58 |
+
`is_trivially_move_constructible_v<``Tᵢ``>` is `true` for all i, this
|
| 59 |
+
constructor is trivial.
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
template<class T> constexpr variant(T&& t) noexcept(see below);
|
| 63 |
```
|
| 64 |
|
| 65 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 66 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ` for which `Tᵢ`` x[] =`
|
| 67 |
+
`{std::forward<T>(t)};` is well-formed for some invented variable `x`.
|
| 68 |
+
The overload *FUN*(Tⱼ) selected by overload resolution for the
|
| 69 |
+
expression *FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ`
|
| 70 |
+
which is the type of the contained value after construction.
|
| 71 |
+
|
| 72 |
+
*Constraints:*
|
| 73 |
+
|
| 74 |
+
- `sizeof...(Types)` is nonzero,
|
| 75 |
+
- `is_same_v<remove_cvref_t<T>, variant>` is `false`,
|
| 76 |
+
- `remove_cvref_t<T>` is neither a specialization of `in_place_type_t`
|
| 77 |
+
nor a specialization of `in_place_index_t`,
|
| 78 |
+
- `is_constructible_v<``Tⱼ``, T>` is `true`, and
|
| 79 |
+
- the expression *FUN*(`std::forward<T>(t))` (with *FUN* being the
|
| 80 |
+
above-mentioned set of imaginary functions) is well-formed.
|
| 81 |
+
\[*Note 1*:
|
| 82 |
+
variant<string, string> v("abc");
|
| 83 |
+
|
| 84 |
+
is ill-formed, as both alternative types have an equally viable
|
| 85 |
+
constructor for the argument.
|
| 86 |
+
— *end note*]
|
| 87 |
|
| 88 |
*Effects:* Initializes `*this` to hold the alternative type `Tⱼ` and
|
| 89 |
direct-initializes the contained value as if
|
| 90 |
direct-non-list-initializing it with `std::forward<T>(t)`.
|
| 91 |
|
| 92 |
+
*Ensures:* `holds_alternative<``Tⱼ``>(*this)` is `true`.
|
| 93 |
|
| 94 |
*Throws:* Any exception thrown by the initialization of the selected
|
| 95 |
alternative `Tⱼ`.
|
| 96 |
|
| 97 |
+
*Remarks:* The expression inside `noexcept` is equivalent to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
`is_nothrow_constructible_v<``Tⱼ``, T>`. If `Tⱼ`’s selected constructor
|
| 99 |
+
is a constexpr constructor, this constructor is a constexpr constructor.
|
|
|
|
| 100 |
|
| 101 |
``` cpp
|
| 102 |
template<class T, class... Args> constexpr explicit variant(in_place_type_t<T>, Args&&... args);
|
| 103 |
```
|
| 104 |
|
| 105 |
+
*Constraints:*
|
| 106 |
+
|
| 107 |
+
- There is exactly one occurrence of `T` in `Types...` and
|
| 108 |
+
- `is_constructible_v<T, Args...>` is `true`.
|
| 109 |
+
|
| 110 |
*Effects:* Initializes the contained value as if
|
| 111 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 112 |
`std::forward<Args>(args)...`.
|
| 113 |
|
| 114 |
+
*Ensures:* `holds_alternative<T>(*this)` is `true`.
|
| 115 |
|
| 116 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 117 |
`T`.
|
| 118 |
|
| 119 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 120 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
template<class T, class U, class... Args>
|
| 124 |
constexpr explicit variant(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
|
| 125 |
```
|
| 126 |
|
| 127 |
+
*Constraints:*
|
| 128 |
+
|
| 129 |
+
- There is exactly one occurrence of `T` in `Types...` and
|
| 130 |
+
- `is_constructible_v<T, initializer_list<U>&, Args...>` is `true`.
|
| 131 |
+
|
| 132 |
*Effects:* Initializes the contained value as if
|
| 133 |
direct-non-list-initializing an object of type `T` with the arguments
|
| 134 |
`il, std::forward<Args>(args)...`.
|
| 135 |
|
| 136 |
+
*Ensures:* `holds_alternative<T>(*this)` is `true`.
|
| 137 |
|
| 138 |
*Throws:* Any exception thrown by calling the selected constructor of
|
| 139 |
`T`.
|
| 140 |
|
| 141 |
+
*Remarks:* If `T`’s selected constructor is a constexpr constructor,
|
| 142 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
``` cpp
|
| 145 |
template<size_t I, class... Args> constexpr explicit variant(in_place_index_t<I>, Args&&... args);
|
| 146 |
```
|
| 147 |
|
| 148 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
- `I` is less than `sizeof...(Types)` and
|
| 151 |
- `is_constructible_v<``T_I``, Args...>` is `true`.
|
| 152 |
|
| 153 |
+
*Effects:* Initializes the contained value as if
|
| 154 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 155 |
+
`std::forward<Args>(args)...`.
|
| 156 |
+
|
| 157 |
+
*Ensures:* `index()` is `I`.
|
| 158 |
+
|
| 159 |
+
*Throws:* Any exception thrown by calling the selected constructor of
|
| 160 |
+
`T_I`.
|
| 161 |
+
|
| 162 |
+
*Remarks:* If `T_I`’s selected constructor is a constexpr constructor,
|
| 163 |
+
this constructor is a constexpr constructor.
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
template<size_t I, class U, class... Args>
|
| 167 |
constexpr explicit variant(in_place_index_t<I>, initializer_list<U> il, Args&&... args);
|
| 168 |
```
|
| 169 |
|
| 170 |
+
*Constraints:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
- `I` is less than `sizeof...(Types)` and
|
| 173 |
- `is_constructible_v<``T_I``, initializer_list<U>&, Args...>` is
|
| 174 |
`true`.
|
| 175 |
|
| 176 |
+
*Effects:* Initializes the contained value as if
|
| 177 |
+
direct-non-list-initializing an object of type `T_I` with the arguments
|
| 178 |
+
`il, std::forward<Args>(args)...`.
|
| 179 |
|
| 180 |
+
*Ensures:* `index()` is `I`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
+
*Remarks:* If `T_I`’s selected constructor is a constexpr constructor,
|
| 183 |
+
this constructor is a constexpr constructor.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|