mardi 8 septembre 2020

Flexibility of C++'s constexpr if statements

I often come across this situation:

if (A && B)
{
    C();
}
else
{
    D();
}

But when A is constexpr, there is no way to indicate that to the expression if B is not constexpr. Further, the workaround for enabling use of constexpr is ugly:

if constexpr (A)
{
    if (B)
    {
        C();
    }
    else
    {
        D();
    }
}
else
{
    D();
}

Is there a proposal to make constexpr if statements more flexible ie. to consider which of the conditionals are constexpr? And if not, is there a workaround for this situation other than assuming the compiler will do the right thing (which they don't always do).

Aucun commentaire:

Enregistrer un commentaire