Skip to content

Commit 38ee849

Browse files
authored
Merge 2021-02 LWG Motion 4
2 parents 861bac3 + 7a70dbd commit 38ee849

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@
693693
#define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception}
694694
#define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map}
695695
#define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits}
696-
#define @\defnlibxname{cpp_lib_variant}@ 201606L // also in \libheader{variant}
696+
#define @\defnlibxname{cpp_lib_variant}@ 202102L // also in \libheader{variant}
697697
#define @\defnlibxname{cpp_lib_void_t}@ 201411L // also in \libheader{type_traits}
698698
\end{codeblock}
699699

source/utilities.tex

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,41 +5129,67 @@
51295129

51305130
\begin{itemdescr}
51315131
\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:
51375133
\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}
51395163
\end{codeblock}
51405164
for the first form and
51415165
\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}
51435167
\end{codeblock}
51445168
for the second form.
51455169

51465170
\pnum
51475171
\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.
51495173
All such expressions are of the same type and value category.
51505174

51515175
\pnum
51525176
\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{)}$
51565180
for the first form.
51575181

51585182
\pnum
51595183
\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}.
51615187

51625188
\pnum
51635189
\complexity
51645190
For $n \leq 1$, the invocation of the callable object is
51655191
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$.
51675193
For $n > 1$, the invocation of the callable object has
51685194
no complexity requirements.
51695195
\end{itemdescr}

0 commit comments

Comments
 (0)