C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 25 May 2024 11:24:11 -0300
On Friday 24 May 2024 20:30:12 GMT-3 Lorand Szollosi via Std-Proposals wrote:
> While returning something that decomposes to a locked mutex is indeed of
> questionable direct use from my perspective as well, I think we're missing
> the obvious (unless any fellow dev already stated):
> struct getLockedMutex {
> std::mutex m;
> getLockedMutex() { m.lock(); }
> };

We're not.

There's no semantic need to return a locked mutex because no other thread can
have access to the mutex until the function has returned. Therefore, there's
ample opportunity to lock the mutex after the function has returned.

Returning a scoped_lock, however, makes a lot of sense.

This is what I am asking of Frederick: give us three distinct examples of
situations we'd want to return modified immovable types. Maybe expand to more
use-cases where access to the return value slot would be helpful.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Fleet Engineering and Quality

Received on 2024-05-25 14:24:20