C++ Logo


Advanced search

Re: [std-proposals] Fold expression contains 'if constexpr'

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 04 Dec 2022 14:53:34 -0800
On Sunday, 4 December 2022 14:40:25 PST Frederick Virchanza Gotham via Std-
Proposals wrote:
> Is there some how some way that we can allow 'if constexpr' inside a
> fold expression? I know that we can have a fold expression containing
> a lambda (and that the lambda can contain 'if constexpr'), but in this
> example we need 'if constexpr' by itself.

Not the if, but the requires can be in a constant expression (I think)

    if constexpr ((requires{ get<Types>(p)->Method(a); } || ...))
        return tailcall(a...);

You can probably simply solve your problem by writing a recursive function

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2022-12-04 22:53:37