Interfaces and Template Specializations

Björn T. Herzig raichoo at googlemail.com
Sun Jan 11 04:11:37 PST 2009


BCS Wrote:

> 
> try 
> 
> void tester(U)(U u) if(is(U : Plugable) && is(U : Printable))
>  ...
> void tester(U)(U u) if(is(U : Plugable) && !is(U : Printable))
>  ...
> 
> or
> 
> void tester(U)(U u)
> {
>    static if(is(U : Plugable)) u.plug();
>    static if(is(U : Printable)) u.print();
> }
> 
> or something along that line 
> 
> 

Thanks, the idea with negating some expressions came to me last night ^^. It works.

So that would mean that if i would write something that is more specialized i would have to negate every specialization for the default template?

void tester(U)(U u) if (is(U : Plugable) && is(U : Printable))
void tester(U)(U u) if (is(U : Plugable) && !is(U : Printable))
void tester(U)(U u) if (!is(U : Plugable) && is(U : Printable))
void tester(U)(U u) if (is(U : int) && !is(U : Plugable) && !is(U :Printable))
void tester(U)(U u) if (is(U : char) ..........)
//default template
void tester(U)(U u) if (!is(U : Plugable) && !is(U : Printable) && !is(U : int) && !is(U : char))
etc....

I tried this in a little piece of test code and i need to specialize so much with every specialization i add, that the code becomes very unpleasant to write (see attachment, it won't compile) 

Regards,
Björn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interfaces.d
Type: application/octet-stream
Size: 1121 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090111/06fd6b0b/attachment.obj>


More information about the Digitalmars-d mailing list