Default template type for class?

Adam D. Ruppe destructionator at gmail.com
Tue Dec 4 08:58:23 PST 2012


> How can I create a default type so that I can call it like 
> myclass.myfunc()?

Can't do that. Best you can do is myclass!().myfunc, then it will 
use the default type (write it is (T = int) bw) but you have to 
put in the !() to actually use the template.

There's a patch for the compiler to change this, but the compiler 
devs are split on if it is actually a good idea or not, because 
of a few cases, one I remember is:

template foo(T = int) {}

alias foo bar; // is bar == foo or is bar == foo!int ?

bar!float; // legal or illegal? It is legal today, but with the 
patch it becomes questionable


More information about the Digitalmars-d-learn mailing list