tmp/tmpft4sxii7/{from.md → to.md}
RENAMED
|
@@ -1,109 +1,111 @@
|
|
| 1 |
#### Assignment <a id="variant.assign">[[variant.assign]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
-
variant& operator=(const variant& rhs);
|
| 5 |
```
|
| 6 |
|
| 7 |
Let j be `rhs.index()`.
|
| 8 |
|
| 9 |
*Effects:*
|
| 10 |
|
| 11 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
`
|
| 19 |
-
|
| 20 |
-
- equivalent to `operator=(variant(rhs))`.
|
| 21 |
|
| 22 |
*Returns:* `*this`.
|
| 23 |
|
| 24 |
-
*
|
| 25 |
|
| 26 |
-
*Remarks:* This
|
| 27 |
-
|
| 28 |
-
`
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
``` cpp
|
| 31 |
-
variant& operator=(variant&& rhs) noexcept(see below);
|
| 32 |
```
|
| 33 |
|
| 34 |
Let j be `rhs.index()`.
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
*Effects:*
|
| 37 |
|
| 38 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
- equivalent to `emplace<`j`>(get<`j`>(std::move(rhs)))`.
|
| 45 |
|
| 46 |
*Returns:* `*this`.
|
| 47 |
|
| 48 |
-
*Remarks:*
|
| 49 |
-
|
| 50 |
-
is `true` for all i
|
|
|
|
|
|
|
| 51 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_move_assignable_v<``Tᵢ``>`
|
| 52 |
for all i.
|
| 53 |
|
| 54 |
- If an exception is thrown during the call to `Tⱼ`’s move construction
|
| 55 |
-
(with j being `rhs.index()
|
| 56 |
- If an exception is thrown during the call to `Tⱼ`’s move assignment,
|
| 57 |
the state of the contained value is as defined by the exception safety
|
| 58 |
guarantee of `Tⱼ`’s move assignment; `index()` will be j.
|
| 59 |
|
| 60 |
``` cpp
|
| 61 |
template<class T> variant& operator=(T&& t) noexcept(see below);
|
| 62 |
```
|
| 63 |
|
| 64 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 65 |
-
function *FUN*(Tᵢ) for each alternative type `Tᵢ`
|
| 66 |
-
|
| 67 |
-
*FUN*(
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
-
|
| 75 |
-
`
|
| 76 |
-
|
| 77 |
-
-
|
| 78 |
-
|
| 79 |
-
*Postconditions:* `holds_alternative<``Tⱼ``>(*this)` is `true`, with
|
| 80 |
-
`Tⱼ` selected by the imaginary function overload resolution described
|
| 81 |
-
above.
|
| 82 |
-
|
| 83 |
-
*Returns:* `*this`.
|
| 84 |
-
|
| 85 |
-
*Remarks:* This function shall not participate in overload resolution
|
| 86 |
-
unless `is_same_v<decay_t<T>, variant>` is `false`, unless
|
| 87 |
-
`is_assignable_v<``Tⱼ``&, T> && is_constructible_v<``Tⱼ``, T>` is
|
| 88 |
-
`true`, and unless the expression *FUN*(std::forward\<T\>(t)) (with
|
| 89 |
-
*FUN* being the above-mentioned set of imaginary functions) is well
|
| 90 |
-
formed.
|
| 91 |
-
|
| 92 |
-
[*Note 1*:
|
| 93 |
-
|
| 94 |
-
``` cpp
|
| 95 |
variant<string, string> v;
|
| 96 |
v = "abc";
|
| 97 |
-
```
|
| 98 |
|
| 99 |
is ill-formed, as both alternative types have an equally viable
|
| 100 |
constructor for the argument.
|
| 101 |
-
|
| 102 |
— *end note*]
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
| 108 |
```
|
| 109 |
|
|
|
|
| 1 |
#### Assignment <a id="variant.assign">[[variant.assign]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
+
constexpr variant& operator=(const variant& rhs);
|
| 5 |
```
|
| 6 |
|
| 7 |
Let j be `rhs.index()`.
|
| 8 |
|
| 9 |
*Effects:*
|
| 10 |
|
| 11 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 12 |
+
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 13 |
+
value contained in `*this` and sets `*this` to not hold a value.
|
| 14 |
+
- Otherwise, if `index() == `j, assigns the value contained in `rhs` to
|
| 15 |
+
the value contained in `*this`.
|
| 16 |
+
- Otherwise, if either `is_nothrow_copy_constructible_v<``Tⱼ``>` is
|
| 17 |
+
`true` or `is_nothrow_move_constructible_v<``Tⱼ``>` is `false`,
|
| 18 |
+
equivalent to `emplace<`j`>(get<`j`>(rhs))`.
|
| 19 |
+
- Otherwise, equivalent to `operator=(variant(rhs))`.
|
|
|
|
| 20 |
|
| 21 |
*Returns:* `*this`.
|
| 22 |
|
| 23 |
+
*Ensures:* `index() == rhs.index()`.
|
| 24 |
|
| 25 |
+
*Remarks:* This operator is defined as deleted unless
|
| 26 |
+
`is_copy_constructible_v<``Tᵢ``> &&` `is_copy_assignable_v<``Tᵢ``>` is
|
| 27 |
+
`true` for all i. If `is_trivially_copy_constructible_v<``Tᵢ``> &&`
|
| 28 |
+
`is_trivially_copy_assignable_v<``Tᵢ``> &&`
|
| 29 |
+
`is_trivially_destructible_v<``Tᵢ``>` is `true` for all i, this
|
| 30 |
+
assignment operator is trivial.
|
| 31 |
|
| 32 |
``` cpp
|
| 33 |
+
constexpr variant& operator=(variant&& rhs) noexcept(see below);
|
| 34 |
```
|
| 35 |
|
| 36 |
Let j be `rhs.index()`.
|
| 37 |
|
| 38 |
+
*Constraints:* `is_move_constructible_v<``Tᵢ``> &&`
|
| 39 |
+
`is_move_assignable_v<``Tᵢ``>` is `true` for all i.
|
| 40 |
+
|
| 41 |
*Effects:*
|
| 42 |
|
| 43 |
- If neither `*this` nor `rhs` holds a value, there is no effect.
|
| 44 |
+
- Otherwise, if `*this` holds a value but `rhs` does not, destroys the
|
| 45 |
+
value contained in `*this` and sets `*this` to not hold a value.
|
| 46 |
+
- Otherwise, if `index() == `j, assigns `get<`j`>(std::move(rhs))` to
|
| 47 |
+
the value contained in `*this`.
|
| 48 |
+
- Otherwise, equivalent to `emplace<`j`>(get<`j`>(std::move(rhs)))`.
|
|
|
|
| 49 |
|
| 50 |
*Returns:* `*this`.
|
| 51 |
|
| 52 |
+
*Remarks:* If `is_trivially_move_constructible_v<``Tᵢ``> &&`
|
| 53 |
+
`is_trivially_move_assignable_v<``Tᵢ``> &&`
|
| 54 |
+
`is_trivially_destructible_v<``Tᵢ``>` is `true` for all i, this
|
| 55 |
+
assignment operator is trivial. The expression inside `noexcept` is
|
| 56 |
+
equivalent to:
|
| 57 |
`is_nothrow_move_constructible_v<``Tᵢ``> && is_nothrow_move_assignable_v<``Tᵢ``>`
|
| 58 |
for all i.
|
| 59 |
|
| 60 |
- If an exception is thrown during the call to `Tⱼ`’s move construction
|
| 61 |
+
(with j being `rhs.index()`), the `variant` will hold no value.
|
| 62 |
- If an exception is thrown during the call to `Tⱼ`’s move assignment,
|
| 63 |
the state of the contained value is as defined by the exception safety
|
| 64 |
guarantee of `Tⱼ`’s move assignment; `index()` will be j.
|
| 65 |
|
| 66 |
``` cpp
|
| 67 |
template<class T> variant& operator=(T&& t) noexcept(see below);
|
| 68 |
```
|
| 69 |
|
| 70 |
Let `Tⱼ` be a type that is determined as follows: build an imaginary
|
| 71 |
+
function *FUN*(Tᵢ) for each alternative type `Tᵢ` for which `Tᵢ`` x[] =`
|
| 72 |
+
`{std::forward<T>(t)};` is well-formed for some invented variable `x`.
|
| 73 |
+
The overload *FUN*(Tⱼ) selected by overload resolution for the
|
| 74 |
+
expression *FUN*(std::forward\<T\>(t)) defines the alternative `Tⱼ`
|
| 75 |
+
which is the type of the contained value after assignment.
|
| 76 |
+
|
| 77 |
+
*Constraints:*
|
| 78 |
+
|
| 79 |
+
- `is_same_v<remove_cvref_t<T>, variant>` is `false`,
|
| 80 |
+
- `is_assignable_v<``Tⱼ``&, T> && is_constructible_v<``Tⱼ``, T>` is
|
| 81 |
+
`true`, and
|
| 82 |
+
- the expression *FUN*(std::forward\<T\>(t)) (with *FUN* being the
|
| 83 |
+
above-mentioned set of imaginary functions) is well-formed.
|
| 84 |
+
\[*Note 1*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
variant<string, string> v;
|
| 86 |
v = "abc";
|
|
|
|
| 87 |
|
| 88 |
is ill-formed, as both alternative types have an equally viable
|
| 89 |
constructor for the argument.
|
|
|
|
| 90 |
— *end note*]
|
| 91 |
|
| 92 |
+
*Effects:*
|
| 93 |
+
|
| 94 |
+
- If `*this` holds a `Tⱼ`, assigns `std::forward<T>(t)` to the value
|
| 95 |
+
contained in `*this`.
|
| 96 |
+
- Otherwise, if `is_nothrow_constructible_v<``Tⱼ``, T> ||`
|
| 97 |
+
`!is_nothrow_move_constructible_v<``Tⱼ``>` is `true`, equivalent to
|
| 98 |
+
`emplace<`j`>(std::forward<T>(t))`.
|
| 99 |
+
- Otherwise, equivalent to `operator=(variant(std::forward<T>(t)))`.
|
| 100 |
+
|
| 101 |
+
*Ensures:* `holds_alternative<``Tⱼ``>(*this)` is `true`, with `Tⱼ`
|
| 102 |
+
selected by the imaginary function overload resolution described above.
|
| 103 |
+
|
| 104 |
+
*Returns:* `*this`.
|
| 105 |
+
|
| 106 |
+
*Remarks:* The expression inside `noexcept` is equivalent to:
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
is_nothrow_assignable_v<Tⱼ&, T> && is_nothrow_constructible_v<Tⱼ, T>
|
| 110 |
```
|
| 111 |
|