Why do we have transitive const, again?

Jonathan M Davis jmdavisProg at gmx.com
Fri Sep 23 11:47:21 PDT 2011


On Friday, September 23, 2011 11:21 Mehrdad wrote:
> Er, you answered a question about const with an answer about immutable. :\

I gave more reasons than just immutability.

> My point is, what in the world does transitive const have to do with
> transitive immutable?
> Can't you have immutable(T) be transitive while const(T) being "normal",
> as in C/C++? If not, why not?

Anything which is const could actually be immutable. immutable(T) is 
implicitly convertible to const(T). It would be _incredibly_ limiting to 
immutable for it to be otherwise. You'd have to duplicate functions all over 
the place so that you had a const and an immutable version, and that results 
in a combinatorial explosion if you're dealing with multiple function 
parameters which could be either const or immutable. So, if you need 
transitive immutable, you need transitive const.

- Jonathan M Davis


More information about the Digitalmars-d mailing list