Template in interface ?

TSalm TSalm at free.fr
Sat Feb 28 15:18:59 PST 2009


Hello,

I need to do something like this :

/* ---- CODE ---- */
import tango.io.Stdout;


interface I
{
   bool cmpType(U)(U val);
}

class  A(T):I
{
   bool cmpType(U)(U val)
   {
     static if ( is (U==T) )
       return true;
     else
       return false;
   }
}

void main()
{
   I a = new A!(int);

   int tInt = 10;
   double tDouble = 20;
   float tFloat = 30;
   a.cmpType(tInt);
   a.cmpType(tDouble);
   a.cmpType(tFloat);
}
/* ---END CODE ---- */

But it's not allow by the compiler when there's no problem when change the  
line:
   I a = new A!(int);
By
   A a = new A!(int);

:-(

Does something have an idea on how to do something like this ?

Thanks in advance,
Tsalm


More information about the Digitalmars-d-learn mailing list