C++ Logo

std-proposals

Advanced search

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

From: Frank Zingsheim <f.zingsheim_at_[hidden]>
Date: Mon, 09 Nov 2020 21:19:09 +0100
Hello Barry and Jason

I was confused by the `template` keyword in front of the `for...` which
I did not find in the proposal.

I have worked in the usage of the `for...` in on the working branch
`progress` of my proposal (see https://github.com/zingsheim/ProposalTer
naryFold/blob/9b8fdf1/ProposalTernaryFold.md#a-expansion-statements-
for-p1306r1-6). Can you check if I understood the usage of `for...`
correctly, or if there is maybe a more compact formulation possible
with the `for...` proposal.

 Frank

>
> 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-09 14:19:14