C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Some question on C++26 `template for` syntax

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Thu, 14 Aug 2025 09:38:41 +0200
czw., 14 sie 2025 o 06:51 Oliver Hunt via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
>
>
> On Aug 13, 2025, at 9:41 PM, 叶易安 via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> C++26 `static reflection` proposal wanna to bring a syntax called `template for`. We know that C++17 introduced one similar thing called `if constexpr`, So why not make the style unified and call it `for constexpr` ?
>
>
> template for is not a constexpr, so this would be incorrect.
>
> `if constexpr` is an if that is guaranteed to be evaluated at compile time, template for is just a for loop where each “iteration” may have a different type. The type unrolling occurs at compile time, but the body of the for loop is not evaluated at compile time, which is what constexpr would be saying.
>

I think the only analogy that already exist today in C++ that could be
used is `, ...`:

```
for... (auto& i : { x... }) foo(i);
(foo(x), ...);
```

But probably `template for` is more friendly for beginners as it has a
name that is easier to find documentation for.

> —Oliver
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-08-14 07:38:55