C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 13 Jan 2026 23:53:16 +0100
    return ! if   could be also written as       return not if   improving it perhaps or not.     but I don't think that applying the ! operator helps with your proposal acceptance.   next you continue with       return transform if   calling a function transform(parameter)   I would concentrate on the 'return if' case first and foremost   and again, it has the same basic semantic as .try? a conditional return. Except that .try? implicitly returns with some value and provides another value for the expression itself. So return if is the simple case of .try? and .try? can provide its full functionality.   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 13.01.2026 23:40 Betreff:Re: [std-proposals] return if An:std-proposals <std-proposals_at_[hidden]>; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Tue, Jan 13, 2026 at 6:06 PM Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote: > > > > 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. I deeply fear that I'll be lambasted for suggesting this . . . but how about:    return ! if SomeFunction(); which would become:    if ( decltype(auto) x = SomeFunction() ) return !x; So just just to be crystal clear about what I'm proposing, here's the ordinary one:    return if SomeFunction()     =>    if ( decltype(auto) x = SomeFunction() ) return x; And here's the inverted one:    return ! if SomeFunction()     =>    if ( decltype(auto) x = SomeFunction() ) return !x; -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals  

Received on 2026-01-13 23:09:11