tmp/tmpzvi71mq7/{from.md → to.md}
RENAMED
|
@@ -49,28 +49,35 @@ namespace std {
|
|
| 49 |
constexpr bool valueless_by_exception() const noexcept;
|
| 50 |
constexpr size_t index() const noexcept;
|
| 51 |
|
| 52 |
// [variant.swap], swap
|
| 53 |
constexpr void swap(variant&) noexcept(see below);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
};
|
| 55 |
}
|
| 56 |
```
|
| 57 |
|
| 58 |
Any instance of `variant` at any given time either holds a value of one
|
| 59 |
of its alternative types or holds no value. When an instance of
|
| 60 |
`variant` holds a value of alternative type `T`, it means that a value
|
| 61 |
of type `T`, referred to as the `variant` object’s *contained value*, is
|
| 62 |
-
|
| 63 |
-
are not permitted to use additional storage, such as dynamic memory, to
|
| 64 |
-
allocate the contained value.
|
| 65 |
|
| 66 |
All types in `Types` shall meet the *Cpp17Destructible* requirements (
|
| 67 |
[[cpp17.destructible]]).
|
| 68 |
|
| 69 |
A program that instantiates the definition of `variant` with no template
|
| 70 |
arguments is ill-formed.
|
| 71 |
|
|
|
|
|
|
|
|
|
|
| 72 |
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 73 |
|
| 74 |
In the descriptions that follow, let i be in the range \[`0`,
|
| 75 |
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types`.
|
| 76 |
|
|
@@ -98,11 +105,11 @@ equivalent to `is_nothrow_default_constructible_v<``T₀``>`.
|
|
| 98 |
constexpr variant(const variant& w);
|
| 99 |
```
|
| 100 |
|
| 101 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 102 |
same alternative as `w` and direct-initializes the contained value with
|
| 103 |
-
`
|
| 104 |
`variant` to not hold a value.
|
| 105 |
|
| 106 |
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 107 |
i.
|
| 108 |
|
|
@@ -117,12 +124,12 @@ constexpr variant(variant&& w) noexcept(see below);
|
|
| 117 |
|
| 118 |
*Constraints:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 119 |
|
| 120 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 121 |
same alternative as `w` and direct-initializes the contained value with
|
| 122 |
-
`
|
| 123 |
-
the `variant` to not hold a value.
|
| 124 |
|
| 125 |
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 126 |
|
| 127 |
*Remarks:* The exception specification is equivalent to the logical of
|
| 128 |
`is_nothrow_move_constructible_v<``Tᵢ``>` for all i. If
|
|
@@ -276,11 +283,11 @@ Let j be `rhs.index()`.
|
|
| 276 |
value contained in `*this` and sets `*this` to not hold a value.
|
| 277 |
- Otherwise, if `index() == `j, assigns the value contained in `rhs` to
|
| 278 |
the value contained in `*this`.
|
| 279 |
- Otherwise, if either `is_nothrow_copy_constructible_v<``Tⱼ``>` is
|
| 280 |
`true` or `is_nothrow_move_constructible_v<``Tⱼ``>` is `false`,
|
| 281 |
-
equivalent to `emplace<`j`>(
|
| 282 |
- Otherwise, equivalent to `operator=(variant(rhs))`.
|
| 283 |
|
| 284 |
*Ensures:* `index() == rhs.index()`.
|
| 285 |
|
| 286 |
*Returns:* `*this`.
|
|
@@ -304,13 +311,14 @@ Let j be `rhs.index()`.
|
|
| 304 |
*Effects:*
|
| 305 |
|
| 306 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 307 |
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 308 |
value contained in `*this` and sets `*this` to not hold a value.
|
| 309 |
-
- Otherwise, if `index() == `j, assigns `
|
| 310 |
-
the value contained in `*this`.
|
| 311 |
-
- Otherwise, equivalent to
|
|
|
|
| 312 |
|
| 313 |
*Returns:* `*this`.
|
| 314 |
|
| 315 |
*Remarks:* If `is_trivially_move_constructible_v<``Tᵢ``> &&`
|
| 316 |
`is_trivially_move_assignable_v<``Tᵢ``> &&`
|
|
@@ -508,24 +516,25 @@ requirements [[swappable.requirements]].
|
|
| 508 |
*Effects:*
|
| 509 |
|
| 510 |
- If `valueless_by_exception() && rhs.valueless_by_exception()` no
|
| 511 |
effect.
|
| 512 |
- Otherwise, if `index() == rhs.index()`, calls
|
| 513 |
-
`swap(
|
|
|
|
| 514 |
- Otherwise, exchanges values of `rhs` and `*this`.
|
| 515 |
|
| 516 |
*Throws:* If `index() == rhs.index()`, any exception thrown by
|
| 517 |
-
`swap(
|
| 518 |
-
Otherwise, any exception thrown by the move constructor of
|
| 519 |
-
with i being `index()` and j being `rhs.index()`.
|
| 520 |
|
| 521 |
*Remarks:* If an exception is thrown during the call to function
|
| 522 |
-
`swap(
|
| 523 |
-
values of `*this` and of `rhs` are determined by the exception
|
| 524 |
-
guarantee of `swap` for lvalues of `Tᵢ` with i being `index()`.
|
| 525 |
-
exception is thrown during the exchange of the values of `*this`
|
| 526 |
-
`rhs`, the states of the values of `*this` and of `rhs` are
|
| 527 |
-
by the exception safety guarantee of `variant`’s move
|
| 528 |
-
exception specification is equivalent to the logical of
|
| 529 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_swappable_v<``Tᵢ``>`
|
| 530 |
for all i.
|
| 531 |
|
|
|
|
| 49 |
constexpr bool valueless_by_exception() const noexcept;
|
| 50 |
constexpr size_t index() const noexcept;
|
| 51 |
|
| 52 |
// [variant.swap], swap
|
| 53 |
constexpr void swap(variant&) noexcept(see below);
|
| 54 |
+
|
| 55 |
+
// [variant.visit], visitation
|
| 56 |
+
template<class Self, class Visitor>
|
| 57 |
+
constexpr decltype(auto) visit(this Self&&, Visitor&&);
|
| 58 |
+
template<class R, class Self, class Visitor>
|
| 59 |
+
constexpr R visit(this Self&&, Visitor&&);
|
| 60 |
};
|
| 61 |
}
|
| 62 |
```
|
| 63 |
|
| 64 |
Any instance of `variant` at any given time either holds a value of one
|
| 65 |
of its alternative types or holds no value. When an instance of
|
| 66 |
`variant` holds a value of alternative type `T`, it means that a value
|
| 67 |
of type `T`, referred to as the `variant` object’s *contained value*, is
|
| 68 |
+
nested within [[intro.object]] the `variant` object.
|
|
|
|
|
|
|
| 69 |
|
| 70 |
All types in `Types` shall meet the *Cpp17Destructible* requirements (
|
| 71 |
[[cpp17.destructible]]).
|
| 72 |
|
| 73 |
A program that instantiates the definition of `variant` with no template
|
| 74 |
arguments is ill-formed.
|
| 75 |
|
| 76 |
+
If a program declares an explicit or partial specialization of
|
| 77 |
+
`variant`, the program is ill-formed, no diagnostic required.
|
| 78 |
+
|
| 79 |
#### Constructors <a id="variant.ctor">[[variant.ctor]]</a>
|
| 80 |
|
| 81 |
In the descriptions that follow, let i be in the range \[`0`,
|
| 82 |
`sizeof...(Types)`), and `Tᵢ` be the iᵗʰ type in `Types`.
|
| 83 |
|
|
|
|
| 105 |
constexpr variant(const variant& w);
|
| 106 |
```
|
| 107 |
|
| 108 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 109 |
same alternative as `w` and direct-initializes the contained value with
|
| 110 |
+
*`GET`*`<j>(w)`, where `j` is `w.index()`. Otherwise, initializes the
|
| 111 |
`variant` to not hold a value.
|
| 112 |
|
| 113 |
*Throws:* Any exception thrown by direct-initializing any `Tᵢ` for all
|
| 114 |
i.
|
| 115 |
|
|
|
|
| 124 |
|
| 125 |
*Constraints:* `is_move_constructible_v<``Tᵢ``>` is `true` for all i.
|
| 126 |
|
| 127 |
*Effects:* If `w` holds a value, initializes the `variant` to hold the
|
| 128 |
same alternative as `w` and direct-initializes the contained value with
|
| 129 |
+
*`GET`*`<j>(std::move(w))`, where `j` is `w.index()`. Otherwise,
|
| 130 |
+
initializes the `variant` to not hold a value.
|
| 131 |
|
| 132 |
*Throws:* Any exception thrown by move-constructing any `Tᵢ` for all i.
|
| 133 |
|
| 134 |
*Remarks:* The exception specification is equivalent to the logical of
|
| 135 |
`is_nothrow_move_constructible_v<``Tᵢ``>` for all i. If
|
|
|
|
| 283 |
value contained in `*this` and sets `*this` to not hold a value.
|
| 284 |
- Otherwise, if `index() == `j, assigns the value contained in `rhs` to
|
| 285 |
the value contained in `*this`.
|
| 286 |
- Otherwise, if either `is_nothrow_copy_constructible_v<``Tⱼ``>` is
|
| 287 |
`true` or `is_nothrow_move_constructible_v<``Tⱼ``>` is `false`,
|
| 288 |
+
equivalent to `emplace<`j`>(`*`GET`*`<`j`>(rhs))`.
|
| 289 |
- Otherwise, equivalent to `operator=(variant(rhs))`.
|
| 290 |
|
| 291 |
*Ensures:* `index() == rhs.index()`.
|
| 292 |
|
| 293 |
*Returns:* `*this`.
|
|
|
|
| 311 |
*Effects:*
|
| 312 |
|
| 313 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 314 |
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 315 |
value contained in `*this` and sets `*this` to not hold a value.
|
| 316 |
+
- Otherwise, if `index() == `j, assigns *`GET`*`<`j`>(std::move(rhs))`
|
| 317 |
+
to the value contained in `*this`.
|
| 318 |
+
- Otherwise, equivalent to
|
| 319 |
+
`emplace<`j`>(`*`GET`*`<`j`>(std::move(rhs)))`.
|
| 320 |
|
| 321 |
*Returns:* `*this`.
|
| 322 |
|
| 323 |
*Remarks:* If `is_trivially_move_constructible_v<``Tᵢ``> &&`
|
| 324 |
`is_trivially_move_assignable_v<``Tᵢ``> &&`
|
|
|
|
| 516 |
*Effects:*
|
| 517 |
|
| 518 |
- If `valueless_by_exception() && rhs.valueless_by_exception()` no
|
| 519 |
effect.
|
| 520 |
- Otherwise, if `index() == rhs.index()`, calls
|
| 521 |
+
`swap(`*`GET`*`<`i`>(*this), `*`GET`*`<`i`>(rhs))` where i is
|
| 522 |
+
`index()`.
|
| 523 |
- Otherwise, exchanges values of `rhs` and `*this`.
|
| 524 |
|
| 525 |
*Throws:* If `index() == rhs.index()`, any exception thrown by
|
| 526 |
+
`swap(`*`GET`*`<`i`>(*this), `*`GET`*`<`i`>(rhs))` with i being
|
| 527 |
+
`index()`. Otherwise, any exception thrown by the move constructor of
|
| 528 |
+
`Tᵢ` or `Tⱼ` with i being `index()` and j being `rhs.index()`.
|
| 529 |
|
| 530 |
*Remarks:* If an exception is thrown during the call to function
|
| 531 |
+
`swap(`*`GET`*`<`i`>(*this), `*`GET`*`<`i`>(rhs))`, the states of the
|
| 532 |
+
contained values of `*this` and of `rhs` are determined by the exception
|
| 533 |
+
safety guarantee of `swap` for lvalues of `Tᵢ` with i being `index()`.
|
| 534 |
+
If an exception is thrown during the exchange of the values of `*this`
|
| 535 |
+
and `rhs`, the states of the values of `*this` and of `rhs` are
|
| 536 |
+
determined by the exception safety guarantee of `variant`’s move
|
| 537 |
+
constructor. The exception specification is equivalent to the logical of
|
| 538 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_swappable_v<``Tᵢ``>`
|
| 539 |
for all i.
|
| 540 |
|