Why the need for an only const ref?

Janice Caron caron800 at googlemail.com
Fri Nov 30 22:17:16 PST 2007


On 11/30/07, Jesse Phillips <jessekphillips at gmail.com> wrote:
> What is the need for a X const x which lets you change the object in x
> but not reassign it to another X?

It's not needed at all. What you're describing is "head const", and
Walter just ditched it.

Head-constness is a purely local thing. It's always possible to do without it.

For reference-objects (i.e. classes) you only need
    mutable ref, mutable data
    mutable ref, const data
    const ref, const data

because const is transitive in D.

For non-reference-objects (i.e. everything else) you only need
    mutable data
    const data

(...and the same holds for invariant)



More information about the Digitalmars-d mailing list