C++ Logo


Advanced search

Re: [std-proposals] Copy-construct, move-construct, and PR-construct

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 21 Aug 2023 11:08:58 -0400
On Mon, Aug 21, 2023 at 11:04 AM Nikl Kelbon via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hmm, may this problem be solved by 'inline' structs/ variables?
> Like
> inline optional o = foo(); // stores all fields separatelly
> return o.value; // return 'field' which is local value really here, so NRVO possible

That's not how NRVO works. It is only permitted in the case of `return
<local_variable>;`, not `return <local_variable>.<member>;`. It would
be impossible to implement it in the way you're talking about, since
it is the caller who provides storage for the return value. And thus,
the caller would have to know to provide enough storage for `o`.

Received on 2023-08-21 15:09:11