C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::contains_mutable

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sun, 02 Jul 2023 06:57:59 +0100
Hi,

On 1 July 2023 23:47:34 BST, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>On Sat, Jul 1, 2023 at 11:33 PM Frederick Virchanza Gotham
><cauldwell.thomas_at_[hidden]> wrote:
>> I would have a synchronisation
>> issue on the non-atomic boolean if it were to be edited when a
>> shared_mutex is locked in shared mode.
>
>
>Actually this is why there should be two new additions to <type_traits>:
>
> std::contains_mutable
> std::contains_nonatomic_mutable
>
>The former will be true for any class that has a mutable member. The
>latter will be true for any class that has a mutable member but only
>if the mutable member is non-atomic.

This is entirely misguided. You can have thread-safe classes that have mutable members, and you can also have thread-unsafe classes without mutable members.

Having a unique_ptr member is not much different to a mutable member in this regard, as it doesn't propagate const to its pointee.

Cheers,
Lénárd

Received on 2023-07-02 05:58:05