Read-only array reference (was: Re: Clarifying 'const' terminology)

BCS BCS_member at pathlink.com
Fri Jul 7 23:19:38 PDT 2006


In article <e8n6v9$2csb$1 at digitaldaemon.com>, Hasan Aljudy says...
>
[...]
>I am from a C++/Java background, yet I still don't fully understand const!
>The only thing I understand is that Java doesn't need it because it's 
>higher-level than D, doesn't allow pointer manipulation, and has builtin 
>immutable String class.
>
>I still don't understand why D needs it, or why do some people think so.
>
[...]
>
>Then how about introducing a new type: read-only array reference.
>(The idea is inspired by Java's immutable string class)
>
>It would be a distinct type, but built into the language core.
>It has a different declaration syntax from regular arrays.
>It cannot be casted to anything at all, absolutly no pointer 
>manipulation is allowed either.
>The content of the array cannot be modified (further explanation below).
>The reference itself *can* be modified to refer to another array, but it 
>would still be a read-only reference.
>Any type of regular array reference (dynamic/static/associative) can be 
>converted to a read-only array reference.
>
[...]

Except for the object stuff and, for the most part, the different declaration
syntax, this is just about the same as the const type I have been wanting. A
syntax that says "this array can't be changed" would cover about %95+ of what I
want. Extending this to direct access to public members of classes and structs
would put it up to %99+.





More information about the Digitalmars-d-learn mailing list