Why do we have transitive const, again?

Timon Gehr timon.gehr at gmx.ch
Fri Sep 23 12:01:14 PDT 2011


On 09/23/2011 08:21 PM, Mehrdad wrote:
> Er, you answered a question about const with an answer about immutable. :\
>
> 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?
>

         const(T)
          / \
         /   \
        /     \
       /       \
      /         \
immutable(T)    T


const(T) is a common 'supertype' of immutable(T) and T.

D const means: This could be immutable or mutable. You are not allowed 
to change it because it might be immutable.

C++ const means: This is head-const and you are not allowed to call any 
non-const member functions on that object, well, unless you cast away const.

The two concepts are different. D const is transitive because immutable 
is transitive.


More information about the Digitalmars-d mailing list