C++ Logo


Advanced search

Re: Review Request: Proposal Ternary Right Fold Expression (P1012)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 8 Nov 2020 10:35:00 -0500
On Sun, Nov 8, 2020 at 4:55 AM Frank Zingsheim via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hello Barry
> Thank you for the hint to the other proposals.
> To the first example with "template for (constexpr": This is interesting since it can replace all usages of std::make_index_sequence which usage in general requires a second function definition.However, I cannot find this kind of syntax "template for (constexpr" in https://wg21.link/P1306.

It's there implicitly. The way `for...` works is by unrolling the
range-based `for` loop. The way it unrolls the loop is *specifically*
defined to create a new variable for each iteration, copied from the
definition in the `for...` statement. The variable is never
overwritten by each iteration; you're getting a new variable each
time; it just happens to have the same name.

This allows each iteration variable to have a different type (by
specifying `auto` or another placeholder), but this *also* allows that
variable to be declared `constexpr`, since you're never modifying it.

Received on 2020-11-08 09:35:17