Writing const-correct code in D

Kevin Bealer Kevin_member at pathlink.com
Wed Mar 8 10:35:41 PST 2006


In article <dumhec$21bq$1 at digitaldaemon.com>, xs0 says...
>
>Kevin Bealer wrote:
..
>OK, this is like the 5000th post I've read regarding const correctness 
>and related issues in D. Can we really not come to some kind of an 
>agreement on what would be best? I'm sure if there's a consensus about a 
>solution, Walter will eventually implement it.
>
..
>- conceptually, each class definition (say Foo : Bar) produces two new 
>types, "readonly Foo : readonly Bar" and "Foo : readonly Foo, Bar", the 
>first of which only contains readonly methods, while the second contains 
>all others. That makes it trivial to do verification and overloading, 
>and has a nice feature that there is no need to actually compile the 
>readonly version, as all verification is done statically, so there is no 
>increase in code size etc.

This sounds like it has nearly the same properties as what I'm proposing.  The
main difference seems to be that you can designate methods as only usable in the
readonly case.  (I'm not sure what that would be useful for, though.)

Notice that the inheritance hierarchy described in the paragraph above is the
*same* as what I wrote.

My point, if you read my post, was that you don't need to introduce new keywords
or syntax.  If you want or need the division between const/nonconst for a
particular type, it can be written in existing D.

Kevin





More information about the Digitalmars-d mailing list