importing std.array: empty in a struct messes things up

arturg var.spool.mail700 at gmail.com
Sun Mar 4 20:45:49 UTC 2018


On Sunday, 4 March 2018 at 20:07:06 UTC, visitor wrote:
> On Sunday, 4 March 2018 at 19:53:59 UTC, ag0aep6g wrote:
>> On 03/04/2018 08:45 PM, ag0aep6g wrote:
>>> I don't know what's going on here. The error message doesn't 
>>> make sense to me. Might be a bug in the compiler.
>>
>> This one works:
>>
>> ----
>> struct Stack(T) {
>>     T[] stack;
>>     alias stack this;
>>     bool empty() {return empty(stack);} /* not using UFCS */
>>     import std.array: empty; /* has to come after the method */
>> }
>> ----
>>
>> Looks very much like a compiler bug now. As far as I know, the 
>> order of declarations shouldn't have an effect like that in 
>> structs. And UFCS should also be ok there, as far as I can 
>> tell.
>
> ?????
> https://run.dlang.io/is/Ws0qEx
> https://run.dlang.io/is/Bancgx

struct Stack(T) {
     import std.array: empty;
     T[] stack;
     alias stack this;
     bool empty() { return empty(stack); }
}

void main()
{
     Stack!int stack;
     //bool x = stack.empty; // fails
     bool x = stack.empty(); // works
}


More information about the Digitalmars-d-learn mailing list