C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Filip <fph2137_at_[hidden]>
Date: Tue, 13 Jan 2026 22:51:17 +0100
I see the following meanings:

`return if (foo());`

Should be as discussed before essentially something like:

```
#define RETURN_IF(callable) \
    do { \
        if (decltype(callable()) ret = callable(); static_cast<bool>(ret) == true) { \
            return ret; \
        } \
    } while (false);
```

However I don’t think that adding expression after return should invert the if.
I see it as a default value to be returned instead of value the callable.

`return default_value if (foo());`

The inverted condition should only invert the comparison to false so:
```
#define RETURN_IF(callable) \
    do { \
        if (decltype(callable()) ret = callable(); static_cast<bool>(ret) == false) { \
            return ret; \
        } \
    } while (false);
```


> On 13 Jan 2026, at 19:06, Ville Voutilainen via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Tue, 13 Jan 2026 at 20:02, Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
>>> if (decltype(auto) x = SomeFunction()) return !x;
>> I've used "decltype(auto)" as the return type of a function but not like this.
>>
>> Anyway it would be more readable as:
>>
>> return false if SomeFunction();
>>
>> In this context the 'false' really means 'inverted'. I don't know if that would bug people too much.
>
> That quite clearly should mean that the function returns false if
> SomeFunction() returns true, not that there's some
> inversion of SomeFunction's return value going on.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-01-13 21:51:32