Re:Immer is a library of persistent and immutable data struc...
by munchbunny on Thursday September 12, 2019 @01:30PM
(#20954059)
> What I have specifically is a class that provides a base set of operations and a subclass that lets you do some modifications
Your object isn't actually immutable, it just doesn't let you directly mutate it. That's a really important distinction.
That's a common pattern. In C++, rather than using a subclass for the mutator, use a different (friend) class. The semantics for implicit conversion between two different classes will allow you to accomplish what you are asking for with enforcing no changes from one interface but not the other.
Your object isn't actually immutable, it just doesn't let you directly mutate it. That's a really important distinction.
That's a common pattern. In C++, rather than using a subclass for the mutator, use a different (friend) class. The semantics for implicit conversion between two different classes will allow you to accomplish what you are asking for with enforcing no changes from one interface but not the other.