template definitions spanning modules.

Jason den Dulk public2 at jasondendulk.com
Sun Aug 25 17:46:48 PDT 2013


Hi

Consider the following code

module A;

void xx(T:int)(T t) { .. }
void xx(T:float)(T t) { .. }


module B;
import A;

void xx(T:string)(T t) { .. }

void main()
{
   xx!(int)(4);
   xx(4.5);
   xx("abc");
}


The compiler won't let me do this. It will complain that 
xx!(int)(4) cannot be instantiated with xx(T:string). If I move 
xx(T:string) into its own module, the compiler complains about 
ambiguity. If I put them all in the same module, it works fine.

I read about overload sets in the docs and tried the "alias A.xx 
xx" suggestion, but the compiler didn't like that either.

Is there any way I can make this work without having to put them 
all in the same module?

Thanks in advance.
Jason.


More information about the Digitalmars-d-learn mailing list