string types: const(char)[] and cstring

Walter Bright newshound1 at digitalmars.com
Sat Jun 2 01:51:14 PDT 2007


Frits van Bommel wrote:
> For other cases though, I could see how a "unique" (or similar) type 
> constructor that would allow implicit conversion to both mutable and 
> invariant (and const) types could be useful.
> For instance, if the strings in your example were replaced by mutable 
> arrays, a "unique char[]" return value of .dup could then be assigned to 
> mutable/const/invariant references without needing casts.

We really tried to figure out a way to make "unique" work. It just 
doesn't offer anything useful over a cast(invariant).

The way to create an invariant out of data is to use cast(invariant). As 
with all casts, one has to trust the programmer to use it appropriately. 
After it is cast, the type system will handle enforcement.

You'll be able to cast away invariant, too, but you're on your own if 
you do so.



More information about the Digitalmars-d-announce mailing list