D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5361 - Base template and template arguments
Summary: Base template and template arguments
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-21 00:23 UTC by bearophile_hugs
Modified: 2014-02-06 12:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-12-21 00:23:22 UTC
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 github-bugzilla 2014-02-06 11:17:00 UTC
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