February 23, 2019 template alias argument accepts only class/interface types. | ||||
---|---|---|---|---|
| ||||
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. |
February 24, 2019 Re: template alias argument accepts only class/interface types. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandru Ermicioi | 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. |
Copyright © 1999-2021 by the D Language Foundation