C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Return Value Optimisation whenever you need it (guaranteed elision)

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sun, 16 Jul 2023 11:03:16 -0400
On Sun, Jul 16, 2023, 10:34 AM Fabio Alemagna <falemagn_at_[hidden]> wrote:

> Il giorno dom 16 lug 2023 alle ore 15:13 Arthur O'Dwyer via
> Std-Proposals <std-proposals_at_[hidden]> ha scritto:
> >
> > On Sun, Jul 16, 2023 at 8:48 AM Bjorn Reese via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
> >>
> >> On 7/16/23 13:54, Frederick Virchanza Gotham via Std-Proposals wrote:
> >>
> >> > Emailed him yesterday, nothing back yet. For the time being I will
> >> > re-write the code to accommodate lambdas-with-captures by using
> >> > "std::function<void(void*)>" instead of function pointers. When I have
> >>
> >> Or you could simply write a mutex wrapper that locks in its constructor.
> >
> >
> > Yes, that would be the "practical programming" approach. :) But it's
> true that NRVO-returning a `Wrapper` isn't quite the same thing as
> NRVO-returning a `std::mutex` itself.
> > https://godbolt.org/z/6c54M176G
> > With that approach, you can never afterward get the mutex "out" of the
> Wrapper in order to put it somewhere specific (such as into a
> `std::list<std::mutex>`).
>
> std::mutex is not final, so you can inherit from it, and given are
> adding just behavior, which gets triggered only on construction, and
> no data, it seems to me it's totally safe to do.
>
> See https://godbolt.org/z/dPT83MoGT


You still can't get such an object into a std::list<mutex>, or even into a
variable of type `mutex` on the stack. (You say "it's" totally safe to do,
but you seem to have locked onto the wrong "it.")

Arthur

Received on 2023-07-16 15:03:29