Thread overview | |||||
---|---|---|---|---|---|
|
December 04, 2012 Default template type for class? | ||||
---|---|---|---|---|
| ||||
I have a class static class myclass(T) { static void myfunc(); } which I have to call like myclass!Q.myfunc(); How can I create a default type so that I can call it like myclass.myfunc()? I've tried static class myclass(T = int) and (alias T = int), neither worked. |
December 04, 2012 Re: Default template type for class? | ||||
---|---|---|---|---|
| ||||
Posted in reply to js.mdnq | > 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
|
December 04, 2012 Re: Default template type for class? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | BTW you can do: class myclass_custom(T = int) {} alias myclass_custom!int myclass; Then use myclass.whatever and you get int. If you want a custom type then, you'd use the other name (myclass_custom!ubyte for instance) |
Copyright © 1999-2021 by the D Language Foundation