tmp/tmp775f67d7/{from.md → to.md}
RENAMED
|
@@ -5,37 +5,58 @@ template<class Visitor, class... Variants>
|
|
| 5 |
constexpr see below visit(Visitor&& vis, Variants&&... vars);
|
| 6 |
template<class R, class Visitor, class... Variants>
|
| 7 |
constexpr R visit(Visitor&& vis, Variants&&... vars);
|
| 8 |
```
|
| 9 |
|
| 10 |
-
Let
|
| 11 |
-
|
| 12 |
-
`mᵢ` < `variant_size_v<remove_reference_t<Variantsᵢ``>>` for all
|
| 13 |
-
0 ≤ i < n. For each valid pack `m`, let e(`m`) denote the expression:
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
```
|
| 18 |
|
| 19 |
for the first form and
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
-
INVOKE<R>(std::forward<Visitor>(vis), get<m>(std::forward<
|
| 23 |
```
|
| 24 |
|
| 25 |
for the second form.
|
| 26 |
|
| 27 |
-
*Mandates:* For each valid pack
|
| 28 |
-
|
| 29 |
|
| 30 |
-
*Returns:* e(
|
| 31 |
-
`vars`ᵢ`.index()` for all 0 ≤ i < n. The return type is
|
| 32 |
-
`decltype(`e(
|
| 33 |
|
| 34 |
-
*Throws:* `bad_variant_access` if
|
| 35 |
-
`valueless_by_exception()`.
|
| 36 |
|
| 37 |
*Complexity:* For n ≤ 1, the invocation of the callable object is
|
| 38 |
implemented in constant time, i.e., for n = 1, it does not depend on the
|
| 39 |
-
number of alternative types of `
|
| 40 |
-
|
| 41 |
|
|
|
|
| 5 |
constexpr see below visit(Visitor&& vis, Variants&&... vars);
|
| 6 |
template<class R, class Visitor, class... Variants>
|
| 7 |
constexpr R visit(Visitor&& vis, Variants&&... vars);
|
| 8 |
```
|
| 9 |
|
| 10 |
+
Let *as-variant* denote the following exposition-only function
|
| 11 |
+
templates:
|
|
|
|
|
|
|
| 12 |
|
| 13 |
``` cpp
|
| 14 |
+
template<class... Ts>
|
| 15 |
+
auto&& as-variant(variant<Ts...>& var) { return var; }
|
| 16 |
+
template<class... Ts>
|
| 17 |
+
auto&& as-variant(const variant<Ts...>& var) { return var; }
|
| 18 |
+
template<class... Ts>
|
| 19 |
+
auto&& as-variant(variant<Ts...>&& var) { return std::move(var); }
|
| 20 |
+
template<class... Ts>
|
| 21 |
+
auto&& as-variant(const variant<Ts...>&& var) { return std::move(var); }
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Let n be `sizeof...(Variants)`. For each 0 ≤ i < n, let `Vᵢ` denote the
|
| 25 |
+
type
|
| 26 |
+
`decltype(`*`as-variant`*`(``std::forward<``Variantsᵢ``>(``varsᵢ``)``))`.
|
| 27 |
+
|
| 28 |
+
*Constraints:* `Vᵢ` is a valid type for all 0 ≤ i < n.
|
| 29 |
+
|
| 30 |
+
Let `V` denote the pack of types `Vᵢ`.
|
| 31 |
+
|
| 32 |
+
Let m be a pack of n values of type `size_t`. Such a pack is valid if
|
| 33 |
+
0 ≤ mᵢ < `variant_size_v<remove_reference_t<Vᵢ``>>` for all 0 ≤ i < n.
|
| 34 |
+
For each valid pack m, let e(m) denote the expression:
|
| 35 |
+
|
| 36 |
+
``` cpp
|
| 37 |
+
INVOKE(std::forward<Visitor>(vis), get<m>(std::forward<V>(vars))...) // see [func.require]
|
| 38 |
```
|
| 39 |
|
| 40 |
for the first form and
|
| 41 |
|
| 42 |
``` cpp
|
| 43 |
+
INVOKE<R>(std::forward<Visitor>(vis), get<m>(std::forward<V>(vars))...) // see [func.require]
|
| 44 |
```
|
| 45 |
|
| 46 |
for the second form.
|
| 47 |
|
| 48 |
+
*Mandates:* For each valid pack m, e(m) is a valid expression. All such
|
| 49 |
+
expressions are of the same type and value category.
|
| 50 |
|
| 51 |
+
*Returns:* e(m), where m is the pack for which mᵢ is
|
| 52 |
+
*`as-variant`*`(vars`ᵢ`).index()` for all 0 ≤ i < n. The return type is
|
| 53 |
+
`decltype(`e(m)`)` for the first form.
|
| 54 |
|
| 55 |
+
*Throws:* `bad_variant_access` if
|
| 56 |
+
`(`*`as-variant`*`(vars).valueless_by_exception() || ...)` is `true`.
|
| 57 |
|
| 58 |
*Complexity:* For n ≤ 1, the invocation of the callable object is
|
| 59 |
implemented in constant time, i.e., for n = 1, it does not depend on the
|
| 60 |
+
number of alternative types of `V₀`. For n > 1, the invocation of the
|
| 61 |
+
callable object has no complexity requirements.
|
| 62 |
|