www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Overload sets and templates

reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
This works:

------------------------------
void foo(T)(T t) if(is(T==char)) {}
void foo(T)(T t) if(is(T==int )) {}

void main() { foo(1); }
------------------------------

But if I move the "int" version to a different module, and try to alias 
it into the current module's overload set (like I can with non-templated 
functions), I just get an error that the "char" version of foo conflicts 
with the alias:

------------------------------
module a;
import b;

alias foo = b.foo;
void foo(T)(T t) if(is(T==char)) {}

void main() { foo(1); }
------------------------------
module b;
void foo(T)(T t) if(is(T==int)) {}
------------------------------

What's up with that? Is there a way to do it?
Feb 08 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/08/2014 10:46 AM, Nick Sabalausky wrote:
 This works:

 ------------------------------
 void foo(T)(T t) if(is(T==char)) {}
 void foo(T)(T t) if(is(T==int )) {}

 void main() { foo(1); }
 ------------------------------

 But if I move the "int" version to a different module, and try to alias
 it into the current module's overload set (like I can with non-templated
 functions), I just get an error that the "char" version of foo conflicts
 with the alias:

 ------------------------------
 module a;
 import b;

 alias foo = b.foo;
 void foo(T)(T t) if(is(T==char)) {}

 void main() { foo(1); }
 ------------------------------
 module b;
 void foo(T)(T t) if(is(T==int)) {}
 ------------------------------

 What's up with that? Is there a way to do it?
What you are trying to do should work. I.e. this is a compiler bug.
Feb 08 2014
parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 2/8/2014 11:35 AM, Timon Gehr wrote:
 What you are trying to do should work. I.e. this is a compiler bug.
Thanks. Filed: https://d.puremagic.com/issues/show_bug.cgi?id=12111
Feb 08 2014