[Issue 13372] traits parent does not work on eponymous templates
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Nov 5 11:06:52 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=13372
--- Comment #3 from b2.temp at gmx.com ---
Strangely enough this bug can lead to think that we can detect an eponymous
template:
==========
template isTemplateInstance(alias T : Base!Args, alias Base, Args...)
{
enum isTemplateInstance = is(typeof(T));
}
template isTemplateInstance(T : Base!Args, alias Base, Args...)
{
enum isTemplateInstance = is(T);
}
template isTemplateInstance(T)
{
enum isTemplateInstance = false;
}
template isTemplateInstance(alias T)
{
enum isTemplateInstance = isTemplateInstance!(typeof(T));
}
template isEponymousTemplate(T)
{
static if (is(T == class) || is(T == interface) || is(T == struct) || is(T
== union))
{
enum p = __traits(parent, T).stringof == T.stringof;
enum isEponymousTemplate = p && isTemplateInstance!T;
}
else
enum isEponymousTemplate = false;
}
unittest
{
class A(T){}
struct B(T){}
static assert(isEponymousTemplate!(A!int));
static assert(isEponymousTemplate!(B!int));
static assert(!isEponymousTemplate!int);
template C(T)
{
class C{}
}
static assert(isEponymousTemplate!(C!int));
}
unittest
{
template A(T)
{
class A{}
}
static assert(isEponymousTemplate!(A!int));
template B(T)
{
class A{}
}
static assert(!isEponymousTemplate!(B!int.A));
class C(T){}
static assert(!isEponymousTemplate!int);
A!int a;
static assert(isEponymousTemplate!a);
}
==========
Indeed we can detect it but we can't get the parent !
What's happen is that "isEponymousTemplate" yield true for an eponymous
template because the template itself points to its argument !
--
More information about the Digitalmars-d-bugs
mailing list