An expansion statement
S is equivalent to a
compound-statement
containing instantiations of the
for-range-declaration
(including its implied initialization),
together with the compound-statement of
S, as follows:
- If S is an enumerating expansion statement, S is equivalent to:
{
init-statement
S0
⋮
SN−1
}
where N is the number of elements in the expression-list,
Si is
{
for-range-declaration = Ei;
compound-statement
}
and Ei is the ith element of the expression-list.
- Otherwise, if S is an iterating expansion statement, S is equivalent to:
{
init-statement
static constexpr auto&& range = expansion-initializer;
static constexpr auto begin = begin-expr;
static constexpr auto end = end-expr;
S0
⋮
SN−1
}
where N is the result of evaluating the expression
[] consteval {
std::ptrdiff_t result = 0;
for (auto i = begin; i != end; ++i, ++result);
return result;
}()
and Si is
{
static constexpr auto iter = begin + i;
for-range-declaration = *iter;
compound-statement
}
The variables
range,
begin,
end, and
iter
are defined for exposition only
. [
Note 1:
The instantiation is ill-formed if
range
is not a constant expression (
[expr.const])
. —
end note]
- Otherwise, S is a destructuring expansion statement and S is equivalent to:
{
init-statement
constexpropt auto&& [u0, u1, …, uN−1] = expansion-initializer;
S0
⋮
SN−1
}
where N is the structured binding size of the type of the expansion-initializer and Si is
{
for-range-declaration = ui;
compound-statement
}