Alias vs templates

Jean-Louis Leroy jl at leroy.nyc
Wed Feb 21 18:46:10 UTC 2018


I am trying to figure out a crispier syntax for templatized open 
methods. I am stumbling on this (see comments):

// dmd -run conflict.d
int foo();

struct Foo {
   static int foo(int x) { return x; }
}

alias foo = Foo.foo; // overload with an alias - OK

int bar(T)();
int bar(T)(T x) { return x; } // overloaded function templates - 
OK

int baz(T)();

struct Baz {
   static int baz(T)(T x) { return x; }
}

//alias baz = Baz.baz; // Error: alias conflict.baz conflicts 
with template conflict.baz(T)() at conflict.d(11)

void main()
{
   import std.stdio;
   writeln(foo(42)); // 42
   writeln(bar(666)); // 666
}

Why?


More information about the Digitalmars-d-learn mailing list