Inherited const when you need to mutate
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 10 18:30:33 PDT 2012
On 7/10/12 5:19 PM, H. S. Teoh wrote:
> Isn't there something we can do to improve this situation?
There is, only thing is there's no easy way (without adding some amount
of complication to the language).
Generally const(T) is a supertype of T and immutable(T), meaning it
could originate from either.
There is value in immutable objects that has been well discussed, which
is incompatible with logical constness. We can change the language such
as: a given type X has the option to declare "I want logical const and
for that I'm giving up the possibility of creating immutable(X)". That
keeps things proper for everybody - immutable still has the strong
properties we know and love, and such types can actually use logical const.
A number of refinements are as always possible.
I'm not sure if I was very clear. In brief, logical constness breaks
things only if the original object was immutable.
Andrei
More information about the Digitalmars-d
mailing list