The only real use I can imagine for something like this is template metaprogramming, as with if-constexpr, to achieve similar goals to std::integer_sequence. Something like,
template<int N>
void foo() { … }
void bar() {
for constexpr(int i = 0; i < 10; i++) {
foo<i>();
}
}
But the semantics wouldn’t quite make sense here.
The paper Christof Meerwald just linked seems a good way to approach this.
From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> On Behalf Of Abdullah Qasim via Std-Proposals
Sent: Sunday, May 1, 2022 03:51 AM
To: Jason McKesson via Std-Proposals <std-proposals@lists.isocpp.org>
Cc: Abdullah Qasim <iamminecraftredstoner@outlook.com>
Subject: [std-proposals] constexpr loops
for constexpr ()for consteval () while constexpr ()while consteval () do constexpr {} while ()do consteval {} while () example: for consteval (int i{ 0 }; i < 1’000’000; ++i) {
cout << "LOL”;}Runtime speed is FAST, w/ these loops.
Easy to implement, too.