C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 13 Sep 2023 19:10:07 -0700
On Tuesday, 12 September 2023 13:03:46 PDT Arthur O'Dwyer via Std-Proposals
wrote:
> I'd say that such types were always meant to be supported (because why
> wouldn't they be?), and since C++17 immovable return types have been
> supported, at least in the cases that Just Work (like `return
> std::mutex();`). One certainly can't say that std::mutex wasn't "meant" to
> be returned. It's a class type; of course you can return it from a
> function! (In spirit, although not literally, each constructor of
> std::mutex *is* such a function.)

Yes, we can say that.

It was designed for and during C++11 and until C++17, it wasn't returnable.
The designers never came up with a means to do it and there doesn't seem to
have been any discussion about it.

C++17 made it possible to return this previously unreturnable type. That
doesn't mean it's a good idea. But on the other hand, returning such immovable
types appears to have been the idea of the change in C++17, so we have to
accept that.

anyway, the point isn't that we're *returning* a type. What we're doing is
create it in-place of where it shall exist once the function has returned.
That's what's happening and this is the semantic that should be discussed.
Returning is a means to an end, not the end itself. And that's what Sebastian
and I are reticent about: semantically, it makes no sense to return a mutex.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-09-14 02:10:10