Date: Mon, 25 May 2026 09:11:03 +0200
> On May 23, 2026, at 2:59 PM, Andrey Semashev via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 23 May 2026 14:56, Sebastian Wittmeier via Std-Proposals wrote:
>> If the inner code blocks just create var, a separate function or a
>> lambda can handle it with its return value.
>>
>> Then auto can be used (twice, for the return type and the variable type).
>
> I'm not sure I understand what you're describing, but if you mean
> extracting the body of the `if` statement into a function or lambda then
> this isn't always feasible as it's often too tied with the rest of the
> context of the enclosing function. And extracting a random piece of code
> into a function that doesn't make sense on its own is hardly a desirable
> solution.
It is called an immediately invoked lambda function. This can be used if you want to use auto and also if you want to use const.
One quick comment about the % idea: I think this is really bad. Yes, you could write enough % to extend the lifetime. But then somebody comes along changing the code and introducing one additional level of nesting and the code suddenly breaks (because he forgot to check all occurrences of %).
>
> On 23 May 2026 14:56, Sebastian Wittmeier via Std-Proposals wrote:
>> If the inner code blocks just create var, a separate function or a
>> lambda can handle it with its return value.
>>
>> Then auto can be used (twice, for the return type and the variable type).
>
> I'm not sure I understand what you're describing, but if you mean
> extracting the body of the `if` statement into a function or lambda then
> this isn't always feasible as it's often too tied with the rest of the
> context of the enclosing function. And extracting a random piece of code
> into a function that doesn't make sense on its own is hardly a desirable
> solution.
It is called an immediately invoked lambda function. This can be used if you want to use auto and also if you want to use const.
One quick comment about the % idea: I think this is really bad. Yes, you could write enough % to extend the lifetime. But then somebody comes along changing the code and introducing one additional level of nesting and the code suddenly breaks (because he forgot to check all occurrences of %).
Received on 2026-05-25 07:11:18
