UFCS overrides alias this

Freddy via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 12 13:48:56 PDT 2015


On Sunday, 12 April 2015 at 20:35:06 UTC, anonymous wrote:
> 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;
----test.d
static import std.range;
alias empty=std.range.empty;
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(16): Error: overload alias 'empty' is not a variable
----
No idea what dmd is doing.

However it works with
----
private auto empty(string s){
	static import std.range;
	return std.range.empty(s);
}
----


More information about the Digitalmars-d mailing list