On 2/9/23 12:45, John Chapman wrote: > On Thursday, 9 February 2023 at 19:17:55 UTC, Ali Çehreli wrote: >> I could not figure out eliminating the hard-coded 4. Can we introspect >> the parameter list of a template like 'fun' in the example? If we >> could, then we could get 4 that way. > > Thank you for this. I don't mind hard-coding the N argument. > TemplateArgsOf needs an instantiated template but maybe ```enum N = > count(fun.stringof, ',') + 1``` is good enough.
Hopefully but very fragile: template t(int[] T = [ 1, 2 ]) {} void main() { import std.algorithm : count; enum N = count(t.stringof, ',') + 1; static assert(N == 1); // FAILS } Same thing with any other thing with comma in it e.g. template t(T = anotherTemplate!(1, 2)) {} Ali