Why would

    return if ! InRange(a);

even work?

 

It should probably be (with parantheses around the expression)

    return if !(InRange(a));
vs.

    return if (!InRange(a));

 

the upper one would return false, if inRange is true

the lower one would return true, if inRange is false

 

 

the other combinations are:

    return if (InRange(a));

and

    return if !(!InRange(a));

 

return true, if inRange is true

and

return false, if inRange is false

 

 

I think what confuses most, is that the ! is on the right of the if.

Better write

    return if ();

    return not if ();

or even better

    return false if ();

 

 

Why we are even talking about returning a bool with that construct.

 

 

Let's just implement it with try? and P2561. Not sure, if I did it correctly.

 

// call it like this, one can also call evaluate() returnif()

evaluate(something(param)).try?; // returns if something returns something trueish

 

// define evaluate like this

template<class T>

std::expected<bool, T> evaluate(T t)

{

    if (t)

        return std::unexpected(t);

    else

        return false;

}