Bug 5361 – Base template and template arguments

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-12-21T00:23:00Z
Last change time
2014-02-06T12:06:30Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-12-21T00:23:22Z
Sometimes while I use templates, given a type I want to know what's the template it comes from. So in code like this: struct Foo(T) {} struct Bar(T) {} void main() { alias Foo!int Spam; } I want to know if Spam is an instantiation of Foo or Bar, and sometimes I'd even like to know the typetuple of arguments that has created Spam (here is (int,)). Currently there are some ways to solve this problem (and there's a module in dsource to find the typetuple of the instantiation template arguments), but I'd like a simple to use, robust, safe, and standard way in Phobos or in __traits, because I think this is a common enough need.
Comment #1 by github-bugzilla — 2014-02-06T11:17:00Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/db88295013fabb9a31368af9cf02787125062df3 Fix Issue 5361 - Add TemplateOf and TemplateArgsOf Examples: ```d struct Foo(A, B) {} alias Bar = Foo!(int, real); static assert(__traits(isSame, TemplateOf!Bar, Foo)); static assert(is(TemplateArgsOf!Bar == TypeTuple!(int, real))); ``` https://d.puremagic.com/issues/show_bug.cgi?id=5361 https://github.com/D-Programming-Language/phobos/commit/e6e323175d8ea83aba09d85c6b927d61835c76c3 Merge pull request #1884 from Poita/bug5361 Fix Issue 5361 - Add TemplateOf and TemplateArgsOf