C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Wed, 14 Jan 2026 16:03:32 +0200
On Wed, 14 Jan 2026 at 13:47, Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>
>
> On Wednesday, January 14, 2026, Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> On Tuesday, 13 January 2026 15:50:02 Pacific Standard Time Frederick Virchanza
>> Gotham via Std-Proposals wrote:
>> > No actually it's a bit longer than that:
>> >
>> > if ( decltype(auto) x = SomeFunction() ) return
>> > !static_cast<decltype(x)>(x);
>>
>> Why are you casting x to x's type?
>>
>> And how often do you need to do that anyway?
>
>
>
>
> Just in case SomeFunction returns an Rvalue reference

So what if it does? If your function returns an rvalue reference or it
returns a decltype(auto), that just works,
and if your function returns a prvalue, that also works without the
cast, the returned value is subject to auto-elision
and auto-move.

Received on 2026-01-14 14:03:49