C++ Logo

std-proposals

Advanced search

Re: [std-proposals] constexpr loops

From: William Linkmeyer <wlink10_at_[hidden]>
Date: Sun, 1 May 2022 11:24:35 -0400
This is not a bad idea per-say, but there are other features, libraries and proposals that cover this. Here’s an incomplete list:

Boost.Hana (and others)
The paper Christof linked
‘consteval’
Template recursion (see [1])

[1]:

A static for loop:

template <int First, int Last, typename Lambda>
inline void static_for(Lambda const& f)
{
    if constexpr (First < Last)
      {
         f(std::integral_constant<int, First>{});
         static_for<First + 1, Last>(f);
      }
}

WL

> On May 1, 2022, at 4:23 AM, Jeremy via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-05-01 15:24:38