C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Stop gap required for NRVO until Anton's paper is assimilated

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 18 Jul 2024 16:15:48 +0100
On Thu, Jul 18, 2024 at 11:47 AM Frederick Virchanza Gotham wrote:
>
> enum Status { Success, Retry, Failure };
>
> Widget foo(int const x)
> {
> int i = 0;
>
> return construct_modify<Widget>(
> i, // passed by reference
> [&](auto &a) -> Status
> {
> if ( i++ >= x ) return Failure;
> if ( a.some_observer() ) return Success;
> return Retry;
> },
> [](void) -> Widget { return Widget(-1); }
> );
> }


I have implemented this on the four main compilers, Microsoft VC++,
GNU g++, LLVM clang, Intel ICX:

      https://msvc.godbolt.org/z/6P7xKdn1T

It still works if you turn on the most extreme optimisations.

Received on 2024-07-18 15:16:02