www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - template alias argument accepts only class/interface types.

reply Alexandru Ermicioi <alexandru.ermicioi gmail.com> writes:
Perhaps I missed somewhere, but it seems that you can pass only 
classes or interfaces to alias argument of a template. Trying to 
pass another type (such as int, int[]) yields an error.

Example of issue:
------------------------
void test(alias T)(int o) {
     import std.stdio;
     writeln("coo");
}

void main() {
     int i;
     test!(Object[])(0);
}
------------------------

Try pass Object or IFoo and everything compiles perfectly.
Link to example: https://run.dlang.io/is/jqr9Zi

According to 
https://dlang.org/spec/template.html#TemplateAliasParameter, 
simple types and arrays are excluded from the list of supported 
"alias X" arguments. I'm wondering why do we have such 
limitation? Is there any reasoning at limiting primitive types 
and arrays?

Thank you,
Alexandru.
Feb 23 2019
parent ag0aep6g <anonymous example.com> writes:
On 23.02.19 23:30, Alexandru Ermicioi wrote:
 According to 
 https://dlang.org/spec/template.html#TemplateAliasParameter, simple 
 types and arrays are excluded from the list of supported "alias X" 
 arguments. I'm wondering why do we have such limitation? Is there any 
 reasoning at limiting primitive types and arrays?
As far as I'm aware, there is no good reason. There's a Bugzilla issue for it that also gives some history: https://issues.dlang.org/show_bug.cgi?id=9029 Apparently even Walter has been convinced by now that it's a silly limitation which should be lifted.
Feb 23 2019