|
5129 | 5129 |
|
5130 | 5130 | \begin{itemdescr}
|
5131 | 5131 | \pnum
|
5132 |
| -Let $n$ be \tcode{sizeof...(Variants)}. Let \tcode{m} be a pack of $n$ |
5133 |
| -values of type \tcode{size_t}. Such a pack is called valid if $0 \leq |
5134 |
| -\tcode{m}_i < \tcode{variant_size_v<remove_reference_t<Variants}_i\tcode{>>}$ for |
5135 |
| -all $0 \leq i < n$. For each valid pack $\tcode{m}$, let $e(\tcode{m})$ |
5136 |
| -denote the expression: |
| 5132 | +Let \exposid{as-variant} denote the following exposition-only function templates: |
5137 | 5133 | \begin{codeblock}
|
5138 |
| -@\placeholder{INVOKE}@(std::forward<Visitor>(vis), get<m>(std::forward<Variants>(vars))...) // see \ref{func.require} |
| 5134 | +template<class... Ts> |
| 5135 | + auto&& @\exposid{as-variant}@(variant<Ts...>& var) { return var; } |
| 5136 | +template<class... Ts> |
| 5137 | + auto&& @\exposid{as-variant}@(const variant<Ts...>& var) { return var; } |
| 5138 | +template<class... Ts> |
| 5139 | + auto&& @\exposid{as-variant}@(variant<Ts...>&& var) { return std::move(var); } |
| 5140 | +template<class... Ts> |
| 5141 | + auto&& @\exposid{as-variant}@(const variant<Ts...>&& var) { return std::move(var); } |
| 5142 | +\end{codeblock} |
| 5143 | +Let $n$ be \tcode{sizeof...(Variants)}. |
| 5144 | +For each $0 \leq i < n$, let |
| 5145 | +$\tcode{V}_i$ denote the type\newline |
| 5146 | +\tcode{decltype(\exposid{as-variant}(\tcode{std::forward<$\tcode{Variants}_i$>($\tcode{vars}_i$)}))}. |
| 5147 | + |
| 5148 | +\pnum |
| 5149 | +\constraints |
| 5150 | +$\tcode{V}_i$ is a valid type for all $0 \leq i < n$. |
| 5151 | + |
| 5152 | +\pnum |
| 5153 | +Let \tcode{V} denote the pack of types $\tcode{V}_i$. |
| 5154 | + |
| 5155 | +\pnum |
| 5156 | +Let $m$ be a pack of $n$ values of type \tcode{size_t}. |
| 5157 | +Such a pack is valid if\newline |
| 5158 | +$0 \leq m_i < \tcode{variant_size_v<remove_reference_t<V}_i\tcode{>>}$ |
| 5159 | +for all $0 \leq i < n$. |
| 5160 | +For each valid pack $m$, let $e(m)$ denote the expression: |
| 5161 | +\begin{codeblock} |
| 5162 | +@\placeholder{INVOKE}@(std::forward<Visitor>(vis), get<@$m$@>(std::forward<V>(vars))...) // see \ref{func.require} |
5139 | 5163 | \end{codeblock}
|
5140 | 5164 | for the first form and
|
5141 | 5165 | \begin{codeblock}
|
5142 |
| -@\placeholder{INVOKE}@<R>(std::forward<Visitor>(vis), get<m>(std::forward<Variants>(vars))...) // see \ref{func.require} |
| 5166 | +@\placeholder{INVOKE}@<R>(std::forward<Visitor>(vis), get<@$m$@>(std::forward<V>(vars))...) // see \ref{func.require} |
5143 | 5167 | \end{codeblock}
|
5144 | 5168 | for the second form.
|
5145 | 5169 |
|
5146 | 5170 | \pnum
|
5147 | 5171 | \mandates
|
5148 |
| -For each valid pack \tcode{m}, $e(\tcode{m})$ is a valid expression. |
| 5172 | +For each valid pack $m$, $e(m)$ is a valid expression. |
5149 | 5173 | All such expressions are of the same type and value category.
|
5150 | 5174 |
|
5151 | 5175 | \pnum
|
5152 | 5176 | \returns
|
5153 |
| -$e(\tcode{m})$, where \tcode{m} is the pack for which |
5154 |
| -$\tcode{m}_i$ is \tcode{vars$_i$.index()} for all $0 \leq i < n$. |
5155 |
| -The return type is $\tcode{decltype(}e(\tcode{m})\tcode{)}$ |
| 5177 | +$e(m)$, where $m$ is the pack for which |
| 5178 | +$m_i$ is \tcode{\exposid{as-variant}(vars$_i$).index()} for all $0 \leq i < n$. |
| 5179 | +The return type is $\tcode{decltype(}e(m)\tcode{)}$ |
5156 | 5180 | for the first form.
|
5157 | 5181 |
|
5158 | 5182 | \pnum
|
5159 | 5183 | \throws
|
5160 |
| -\tcode{bad_variant_access} if any \tcode{variant} in \tcode{vars} is \tcode{valueless_by_exception()}. |
| 5184 | +\tcode{bad_variant_access} if |
| 5185 | +\tcode{(\exposid{as-variant}(vars).valueless_by_exception() || ...)} |
| 5186 | +is \tcode{true}. |
5161 | 5187 |
|
5162 | 5188 | \pnum
|
5163 | 5189 | \complexity
|
5164 | 5190 | For $n \leq 1$, the invocation of the callable object is
|
5165 | 5191 | implemented in constant time, i.e., for $n = 1$, it does not depend on
|
5166 |
| -the number of alternative types of $\tcode{Variants}_0$. |
| 5192 | +the number of alternative types of $\tcode{V}_0$. |
5167 | 5193 | For $n > 1$, the invocation of the callable object has
|
5168 | 5194 | no complexity requirements.
|
5169 | 5195 | \end{itemdescr}
|
|
0 commit comments