C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::contains_mutable

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 1 Jul 2023 19:43:07 +0100
On Saturday, July 1, 2023, Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Changing a mutable counts as read-only access from the view from outside
> the class.
>
> You think of non-mutable const accesses to be implicitly thread-safe?
>
> You could possibly reintroduce volatile member functions as thread-safe
> interface?
>
> C++: Been there, tried that?
>



I don't understand what you wrote there.

But anyway, let's say I have two base classes:

    Reservable_CanBeReadOnly
    Reservable_CannotBeReadOnly

The former has two methods, 'Reserve' and 'ReserveReadOnly', while the
latter only has 'Reserve'.

So next I would have:

template<class T>
class Reservable : public std::conditional_t< std::contains_mutable_v<T>,
Reservable_CannotBeReadOnly, Reservable_CanBeReadOnly >
{

};

So if T is a class that has mutable members, then you won't be able to call
the 'ReserveReadOnly' method.

Received on 2023-07-01 18:43:09