Why doesn't this work in D2?

Jacob Carlborg doob at me.com
Mon Jun 28 01:56:45 PDT 2010


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


More information about the Digitalmars-d-learn mailing list