Date: Mon, 12 Jan 2026 13:58:39 +0100
Can be directly done with a macro.
Perhaps soon with new metaprogramming facilities?
-----Ursprüngliche Nachricht-----
Von:Jan Schultke via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Mo 12.01.2026 06:53
Betreff:Re: [std-proposals] return if
An:std-proposals_at_[hidden];
CC:Jan Schultke <janschultke_at_[hidden]>;
The idea isn't bad in a vacuum, but it provides too little value:
if (auto r = some_function()) return r;
// vs.
return if some_function();
The argument you're making with a proposal is that code above is problematic and verbose to a degree where we need compiler support so we can write the code below. I'm not seeing that.
The original does not suffer from multiple evaluations or from some kind of performance problem, or from some major bug potential that cannot be resolved with compiler warnings, or some other major issue. In fact, it only has a single evaluation of some_function(), r is limited to the scope of the if statement, and if you accidentally return something other than r, you may get a warning due to an unused variable. It's quite amazing already. The only downside is that it's a few characters longer, but we'd never see the end of it if we added new compiler features each time there are a dozen characters to be saved.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-01-12 13:14:34
