D-Programming-Language/phobos — pull request #1367 by timotheecour (2013-06-24 01:03:16+00:00)
Title: new std.traits templates: isSame, isSameTypleTuple, GetTemplateParent, GetTemplateArguments, isTemplateInstantiation

defines new std.traits templates:

* isSame
* isSameTypleTuple
* GetTemplateParent
* GetTemplateArguments
* isTemplateInstantiation

These are useful generic traits that can be used

related discussions:

http://forum.dlang.org/post/mailman.1382.1371938670.13711.digitalmars-d@puremagic.com
http://d.puremagic.com/issues/show_bug.cgi?id=4265
In particular, GetTemplateParent, GetTemplateArguments avoid requiring templates to define internal aliases for type parameters, as is currently done in d modules (and always done in C++ templates). GetTemplateParent/GetTemplateArguments removes the need to introduce new compiler __traits.

These traits are also essential in a subsequent pull request I will make to fix std.traits.fullyQualifiedName + friends to work on templated types (currently fullyQualifiedName + friends fail on those)

'isSame' works with pretty much everything I've tried. It wraps around __traits(isSame, a==b) , is(a==b), a==b as required.

Caveats:
* currently I have no way to get this to work with function templates (only struct/class templates). Help welcome.
* isSameTypleTuple may be better placed in std.typetuple. Is there a way to avoid requiring the 1st size_t N argument while giving the same functionality?