This feature request could be also made to a standard library function.

 

 

// Calls the constructor and a setup function. With guaranteed RVO.

T std::factory<T>(params, ..., setup)

 

No need for other language changes or any special exception handling.

 

 

 

// usage:

mutex my_mutex(bool cond)

{

    return std::factory<mutex>(

        [&cond](auto mut) {

            if (cond)

                mut.lock();

        }

    );

}


 

-----Ursprüngliche Nachricht-----
Von: Tiago Freire via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 20.05.2024 11:11
Betreff: Re: [std-proposals] std::elide
An: std-proposals@lists.isocpp.org;
CC: Tiago Freire <tmiguelf@hotmail.com>;
Or just do this instead:

int main(void)
{
   mutex m;
   m.lock();
}


Does exactly the same thing, saves on functions calls, don't have to write a function, don't need to add a language feature, don't have to abuse the language, it actually makes sense from what a mutex is, its shorter, concise, transparent, clear.

Some problems don't need solving because they were never problems to begin with.