C++ Logo

std-proposals

Advanced search

Re: [std-proposals] constexpr loops

From: <rifkin.jer_at_[hidden]>
Date: Sun, 1 May 2022 04:23:23 -0400
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_at_[hidden]> On Behalf Of
Abdullah Qasim via Std-Proposals
Sent: Sunday, May 1, 2022 03:51 AM
To: Jason McKesson via Std-Proposals <std-proposals_at_[hidden]>
Cc: Abdullah Qasim <iamminecraftredstoner_at_[hidden]>
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.


Received on 2022-05-01 08:23:26