Bug 10890 – To find all arguments of an instantiated template

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-25T09:56:00Z
Last change time
2013-08-25T15:57:08Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-08-25T09:56:55Z
Given an instantiated template like: struct Foo(T, U, size_t n) {} alias F1 = Foo!(int, float, 5); In many situations for me it's going to be useful a built-in trait (or a Phobos template with the same semantics) that returns a TypeTuple of the original template plus all the arguments used to instantiate it: __trait(templateArguments, F1) ==> TypeTuple!(Foo, int, float, 5) That means something like this should work: alias TT = __trait(templateArguments, F1); static assert(is(F1 == T[0]!(TT[1 .. $][]))); It should work with variadic templates too. I have tagged this as dmd enhancement, but if a full library implementation is possible, then this is meant just as a Phobos enhancement.
Comment #1 by hsteoh — 2013-08-25T14:13:51Z
One workaround is to define a public alias inside your struct: struct Foo(T...) { alias TemplateArgs = T; ... } alias F1 = Foo!(int, float, 5); alias F1_parms = F1.TemplateArgs; It's not as pretty, but it works.
Comment #2 by andrej.mitrovich — 2013-08-25T15:57:08Z
*** This issue has been marked as a duplicate of issue 4265 ***