C++ Logo


Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 23 Aug 2023 11:28:13 -0400
On Wed, Aug 23, 2023 at 11:07 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> On Wed, Aug 23, 2023 at 3:37 PM Jason McKesson via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Please answer the question that was asked. I asked what the code
> > meant. I did not ask "how this could be implemented". Implementations
> > do not matter at this point. You need to start with an explanation of
> > *what is happening*, not how a compiler will go about making that
> > happen
> Okay here's what it boils down to:
> Classes like 'optional', 'variant' and 'any' have a constructor and
> assignment operator that can take an Lvalue argument or an Rvalue
> argument. This is adequate for classes that are
> uncopiable-but-movable. But this isn't good enough for classes that
> are unmovable-and-uncopiable, for example let's say that a function
> returns a mutex and we want to put that mutex inside an std::optional.
> I keep using the example of a 'mutex' simply because it's right there
> in the standard library and everyone's familiar with it. In the real
> world though it would make more sense to use a Widget or whatever
> (like in Anton's paper on NRVO).
> What I'm suggesting here is that we have a new kind of syntax for
> defining a constructor and assignment operator to allow us to take a
> PRvalue, as well as a new keyword such as '__emplace' so that we can
> control when the PRvalue gets generated. When I say 'generate the
> PRvalue' here, I mean invoke the function/functor that returns the
> class by value.

Prvalue: you keep using that word. I dunna think it means what you
think it means.

"Prvalue" is a classification of an expression. Constructors and
assignment operators can *already* "take a PRvalue":

other_type func();

struct some_type
  some_type(other_type t);

some_type val{func()};

A prvalue is used to initialize the parameter for this constructor.
That matches the literal text of what you asked for. Therefore, your
described functionality does not constitute an actual change to the

The actual description of the behavior you want is substantially
different from the literal text of your request. You seem to want to
capture *unevaluated expressions*, not "prvalues", and then evaluate
those expressions within the function that captured them. *That* is
what we need clarification on. What exactly is being captured, how
much of the expression is "unevaluated", and what it even means to use
the name of that expression within the function.

Again, this is not a matter of implementation; it is a matter of
describing what *exactly* it is you are asking for.

Received on 2023-08-23 15:28:24