C++ Logo

std-proposals

Advanced search

[std-proposals] for loop enhancement

From: Filip <fph2137_at_[hidden]>
Date: Fri, 14 Mar 2025 17:43:19 +0100
I want to ask for your comments about couple of different for loops ideas that I had recently:

1. using enum in for loop:
```
for (auto e : someEnum) {...}
```

Since compiler knows the elements of `ENUM` it should be able to easily unroll the loop or iterate over the elements of enum.

2. Forcing unroll with a keyword and not `#pragma`
```
inline for ( … )
```
It could force the unroll like similar construct does in zig.
This syntax already exists and we could probably easily implement it.

3. Run loop N times
```
for ( 5 )
```
Running for loop N number of times is a common issue e.g. N tries to connect to the server.
This way would not pollute the namespace with additional `int i` that we frankly don’t use.

Received on 2025-03-14 16:43:32