From Jason Turner

[variant.visit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmps0m_v0oc/{from.md → to.md} +33 -6
tmp/tmps0m_v0oc/{from.md → to.md} RENAMED
@@ -10,17 +10,17 @@ template<class R, class Visitor, class... Variants>
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ᵢ``)``))`.
@@ -32,17 +32,17 @@ Let `V` denote the pack of types `Vᵢ`.
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
@@ -58,5 +58,32 @@ expressions are of the same type and value category.
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  Let *as-variant* denote the following exposition-only function
11
  templates:
12
 
13
  ``` cpp
14
  template<class... Ts>
15
+ constexpr auto&& as-variant(variant<Ts...>& var) { return var; }
16
  template<class... Ts>
17
+ constexpr auto&& as-variant(const variant<Ts...>& var) { return var; }
18
  template<class... Ts>
19
+ constexpr auto&& as-variant(variant<Ts...>&& var) { return std::move(var); }
20
  template<class... Ts>
21
+ constexpr 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ᵢ``)``))`.
 
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
 
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
 
63
+ ``` cpp
64
+ template<class Self, class Visitor>
65
+ constexpr decltype(auto) visit(this Self&& self, Visitor&& vis);
66
+ ```
67
+
68
+ Let `V` be
69
+ *`OVERRIDE_REF`*`(Self&&, `*`COPY_CONST`*`(remove_reference_t<Self>, variant))`
70
+ [[forward]].
71
+
72
+ *Constraints:* The call to `visit` does not use an explicit
73
+ *template-argument-list* that begins with a type *template-argument*.
74
+
75
+ *Effects:* Equivalent to:
76
+ `return std::visit(std::forward<Visitor>(vis), (V)self);`
77
+
78
+ ``` cpp
79
+ template<class R, class Self, class Visitor>
80
+ constexpr R visit(this Self&& self, Visitor&& vis);
81
+ ```
82
+
83
+ Let `V` be
84
+ *`OVERRIDE_REF`*`(Self&&, `*`COPY_CONST`*`(remove_reference_t<Self>, variant))`
85
+ [[forward]].
86
+
87
+ *Effects:* Equivalent to:
88
+ `return std::visit<R>(std::forward<Visitor>(vis), (V)self);`
89
+