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: Wed, 17 Jul 2024 21:47:44 +0100
On Wednesday, July 17, 2024, Lénárd Szolnoki wrote:
>
>
> How do I achieve the same thing with P3357, especially with taking care of
> exception safety?
>
>

Sebastian and I are now collaborating on P3357. The first revision will
have too many alterations to list, so everyone will just have to read the
entire thing from start to finish again.

Firstly, 'factory' is renamed to 'construct_modify'.

I haven't put a huge amount of thought into your example, but here's my
first lash at it:

Widget foo(int const i)
{
   struct Exception {};

   try
   {
      return construct_modify<Widget>(i,
        [](Widget &w)
        {
          if ( ! w. some_observer() ) throw Exception();
        });
    }
    catch(Exception const&)
    {
       return Widget(0);
    }
}

Received on 2024-07-17 20:47:46