C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 19 May 2024 22:59:53 +0100
On Sun, May 19, 2024 at 10:49 PM Sebastian Wittmeier wrote:
>
> auto Func() -> mutex m
> {
> if (cond)
> return Func2();
> else
> {
> std::construct(m);
> m.lock();
> return m;
> }
> }


Or maybe like this:

 mutex Func(void)
 {
     try
     {
          if ( cond ) return Func2();
          else
          {
              auto &m = std::construct( /* ctor arguments go here */ );
              m.lock();
              return m;
           }
    }
    catch(...)
    {
          if ( std::is_constructed_already() ) return std::constructed_object();
          std::construct( /* ctor arguments go here */ );
          std::constructed().lock();
          return std::constructed();
    }
 }

Received on 2024-05-19 22:00:04