UFCS overrides alias this

anonymous via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 12 13:35:05 PDT 2015


On Sunday, 12 April 2015 at 20:19:02 UTC, Freddy wrote:
>
> ----test.d
> struct A{
> 	string b;
> 	alias b this;
> }
>
> struct MyRange{
> 	
> }
> char front(MyRange);
> void popFront(ref MyRange);
> bool empty(MyRange);
>
> void test(A a){
> 	a.empty;
> }
> ----
> $ dmd -o- test
> test.d(14): Error: function test.empty (MyRange) is not 
> callable using argument types (A)
> ----
> Is this intended behavior?

string's empty is actually a function in std.array or std.range 
or something, called via UFCS. You don't import std's empty, so 
the call can't match even when the alias this is tried.

Add the following, which brings std's empty into the overload 
set, and it works:

static import std.range;
alias empty = std.range.empty;


More information about the Digitalmars-d mailing list