On 2010-06-28 02:28, BCS wrote:
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.

I don't think I understand what you're showing here. How would I strip off the const/immutable with a template ?

--
/Jacob Carlborg

Reply via email to