The current status of D?

Timon Gehr timon.gehr at gmx.ch
Fri Dec 2 13:08:21 PST 2011


On 12/02/2011 09:57 PM, Mehrdad wrote:
> On 12/2/2011 9:38 AM, Timon Gehr wrote:
>> On 12/02/2011 05:13 PM, Mehrdad wrote:
>>> Actually, regarding my "little problem", why does this given an
>>> error/what's the proper way to fix it?
>>>
>>> class C(T) { inout this(inout(T)) { } }
>>> C!T slice(T)(auto ref T c) { return new C!T(c); }
>>> void main() { [1, 2, 3, 4, 5].slice(); }
>>>
>>> //Test.d(2): Error: cannot implicitly convert expression (new C(items))
>>> of type inout(C) to Test.C!(int[]).C
>>
>> 1. File a bug. inout is apparently not resolved properly by DMD in
>> this case.
> http://d.puremagic.com/issues/show_bug.cgi?id=7053
>
>> 2. Apply this workaround to make the compiler shut up (and probably to
>> make your code less bloated by extraneous template instances as well
>> :o)):
>>
>> class C(T) { inout this(inout(T)) { } }
>> inout(C!T) slice(T)(inout T c){ return new C!T(c); }
>> void main() { [1, 2, 3, 4, 5].slice(); }
> That just propagates it up the stack, though...

It does not, otherwise I would not have called it a workaround. It seems 
only to be a problem for class constructors:

class C(T) { inout this(inout(T)) { } }
inout(C!T) slice(T)(inout T c){ return new C!T(c); }
void main() { static assert(!is(typeof([1, 2, 3, 4, 5].slice())==inout)); }


More information about the Digitalmars-d mailing list