Transitive const sucks

Janice Caron caron800 at googlemail.com
Thu Sep 13 00:25:14 PDT 2007


On 9/13/07, Janice Caron <caron800 at googlemail.com> wrote:
> with non-transitive
> const, one can always write a class differently such that "mutable" is
> never required. Essentially, you replace
>
> class C
> {
>     mutable T x;
> }
>
> with
>
> class C
> {
>     T * x;
> }
>
> Then you can let x be constant, but still modify the actual variable
> itself through *x.

Except of course that using the "mutable" keyword ensures that /only/
class member functions can modify x, /and/ gives you value semantics
instead of pointer semantics to boot.



More information about the Digitalmars-d mailing list