digitalmars.D.learn - Getting the template name of a template instantiation
- =?UTF-8?B?Tm9yZGzDtnc=?= (8/8) Jun 27 2016 If I have a template parameter
- Lodovico Giaretta (3/11) Jun 27 2016 If I recall correctly, std.traits contains a TemplateOf trait,
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/22) Jun 27 2016 Yes, isIntanceOf:
- John (3/11) Jun 27 2016 import std.traits;
- John (4/22) Jun 27 2016 Scratch that, this is what you want:
- =?UTF-8?B?Tm9yZGzDtnc=?= (5/10) Jun 27 2016 I believe this is what
If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?
Jun 27 2016
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote:If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?If I recall correctly, std.traits contains a TemplateOf trait, that should do exactly what you want.
Jun 27 2016
On 06/27/2016 09:54 AM, Lodovico Giaretta wrote:On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote:Yes, isIntanceOf: https://dlang.org/phobos/std_traits.html#isInstanceOf AliIf I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?If I recall correctly, std.traits contains a TemplateOf trait, that should do exactly what you want.
Jun 27 2016
On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote:If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?import std.traits; __traits(identifier, TemplateOf!(S!int));
Jun 27 2016
On Monday, 27 June 2016 at 17:14:23 UTC, John wrote:On Monday, 27 June 2016 at 16:40:09 UTC, Nordlöw wrote:Scratch that, this is what you want: import std.traits; static assert(__traits(isSame, TemplateOf!(S!int), S));If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?import std.traits; __traits(identifier, TemplateOf!(S!int));
Jun 27 2016
On Monday, 27 June 2016 at 17:17:19 UTC, John wrote:I believe this is what import std.traits : isInstanceOf; is for. Thanks! I found both useful.import std.traits; __traits(identifier, TemplateOf!(S!int));Scratch that, this is what you want: import std.traits; static assert(__traits(isSame, TemplateOf!(S!int), S));
Jun 27 2016