C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Wed, 23 Aug 2023 19:32:43 -0800
On Wed, Aug 23, 2023 at 7:26 PM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:

> On Wed, Aug 23, 2023 at 5:31 PM Thiago Macieira via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>> How about instead we add a constructor to std::mutex to allow it to be
>> born locked?
>
>
> Well, because the issue here isn't *really* about making a mutex that's
> locked. That's just a very convenient *concrete example *of the general
> problem. If we gave std::mutex a constructor that allowed it to be born
> locked, then we'd have to invent a *new* concrete example to demonstrate
> the general problem. (Like maybe "making a vector with a given capacity.")
>

...oops, of course that works fine because `std::vector` is
move-constructible!
    std::vector<int> factory() { std::vector<int> v; v.reserve(10); return
v; } // OK, and NRVO-able
So it would have to be more like "making a `std::barrier` that has already
been decremented once," or something like that.
    std::barrier<> factory() { std::barrier<> b(10); b.arrive(5); [[nrvo]]
return b; } // not currently allowed

"Return a locked mutex" is a much more convenient example to talk about. :)

–Arthur

>

Received on 2023-08-24 03:32:57