C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 15 Jan 2026 10:45:50 +0000
On Thu, Jan 15, 2026 at 9:54 AM Filip via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> return if appears to be basically an assert that does not stop your program from running.
>
> Maybe it is better to just use something similar to assert?
>
> ```
> 1. soft_assert(foo());
> 2. soft_assert(foo(), default_return_value);
> ```


No that's not the intention.

Imagine you have a function that retrieves the UUID for a given
signatory on a bank account, and the bank operates in 3 different
countries:

    __uint128_t GetSignatoryID( chrono::time_point date_of_birth,
string_view primary_surname_on_birthcert, string_view
primary_forename_on_birthcert )
    {
        return if manager.GetRegion("Sweden" ).FindRecord(
date_of_birth, primary_surname_on_birthcert,
primary_forename_on_birthcert );
        return if manager.GetRegion("Germany").FindRecord(
date_of_birth, primary_surname_on_birthcert,
primary_forename_on_birthcert );
        return if manager.GetRegion("Japan" ).FindRecord(
date_of_birth, primary_surname_on_birthcert,
primary_forename_on_birthcert );

        return GenerateNewID( date_of_birth,
primary_surname_on_birthcert, primary_forename_on_birthcert );
    }

Actually . . . we might want another new feature for the above code .
. . a feature that takes all the arguments of the enclosing function
and passes them to the callee function, like this:

    __uint128_t GetSignatoryID( std::chrono::time_point date_of_birth,
string_view primary_surname_on_birthcert, string_view
primary_forename_on_birthcert )
    {
        return if manager.GetRegion("Sweden" ).FindRecord( [forward] );
        return if manager.GetRegion("Germany").FindRecord( [forward] );
        return if manager.GetRegion("Japan" ).FindRecord( [forward] );

        return GenerateNewID( [forward] );
    }

But actually I should start a new thread for that other feature . . .
give me a minute.

Received on 2026-01-15 10:46:05