www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: I get how. I don't get why. (more const stuff)

Steven Schveighoffer Wrote:

 const(structtype) means that the structtype itself is not const, and you
 just wasted 7 perfectly good keystrokes typing 'const()' around it since the
 structtype doesn't point anywhere.  This makes no sense to me either...

Actually, if structtype constains any pointers or class references, the things those point to will be constant. It's tail-constness, so the head (what the symbol is bound to) is not constant, but the tail (anything referenced) is. I don't like this, but I think the "head-const" and "tail-const" concepts are here to stay in D, so start thinking of "const" as "tail-const" and "final" as "head-const," and maybe that'll make more sense. This syntax was suggested at the conference: const() Type var; // var is head-const, what "final Type var" means now const(Type) var; // var is tail-const, what "const(Type) var" means now const Type var; // all of var is const, what "final const(Type) var" // mans now. Make more sense? Not really, but it's a different way of looking at it.
Sep 07 2007