C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sun, 19 May 2024 23:49:08 +0200
Solution would be     auto Func() -> mutex m {     if (cond)         return Func2();     else         std::construct(m);         m.lock();         return m; }     Even if the return parameter is named, it is allowed to delegate the construction to another function (here Func2). When an lvalue is returned, it has to be the named return variable (which had to be constructed exactly once).     std::construct similar to std::construct_at?   Or just     m{}; or     mutex m{}; or     std::construct_at(&m);   -----Ursprüngliche Nachricht----- Von:Sebastian Wittmeier <wittmeier_at_[hidden]> Gesendet:So 19.05.2024 23:39 Betreff:AW: [std-proposals] std::elide An:std-proposals_at_[hidden]; One disadvantage of naming is, if Func just calls another NRVO-function returning the mutex.     mutex Func() {     return Func2(); }   mutex Func2() {     return Func3(); }     mutex Func3() {     return mutex{}; }         -----Ursprüngliche Nachricht----- Von:Sebastian Wittmeier <wittmeier_at_[hidden]> Gesendet:So 19.05.2024 23:30 Betreff:AW: [std-proposals] std::elide An:std-proposals_at_[hidden]; As each function with NRVO must know, when the to-be-returned object is constructed that it is meant for return (because then it is constructed in the return slot from the caller), it is no limitation to fix the return variable for the whole function.

Received on 2024-05-19 21:49:10