Why doesn't this work in D2?

BCS none at anon.com
Sun Jun 27 17:28:42 PDT 2010

Hello Jacob,

> That's annoying, specially since "char" is a value type. I would
> preferably have a solution for both D1 and D2. Can I use a template to
> cast/alias away the immutable part?

One solution would be to have templates strip off const/immutable from the 
top level of args.

void F1(T)(T t) { pragam(msg,typeof(t).stringof); }

string s1;
immutable(char[]) s2
char[] s3

F1(s1); // immutable(char)[] // all as normal
F1(s2); // immutable(char)[] // making a mutable copy of a immutable value 
is OK
F1(s3); // char[] // all as normal

void F2(T)(immutable T t) { pragam(msg,typeof(t).stringof); }

F2(s1); // immutable(char[]) // making an immutable copy of a mutable reference 
to immutable data is ok
F2(s2); // immutable(char[]) // all as normal
F2(s3); // error, invalid conversion

This solution would match the proposal that popped up a while ago to allow 
value assignment from const/immutable to mutable. 

... <IXOYE><

More information about the Digitalmars-d-learn mailing list