[Issue 9608] Add introspection for templates
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 23 11:32:38 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9608
--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-03-23 11:32:36 PDT ---
(In reply to comment #0)
> There would be a fair amount of design involved because currently there's no
> kind that expresses a template's parameters outside the template.
I don't think we need to design much. We could provide traits. For example:
template A(alias sym)
{
__traits(getArity, sym); // 2 - or paramCount
__traits(isAliasParam, 0, sym); // 0 == index of param
}
A!((a, b) => a.name < b.name);
template B(alias sym)
{
__traits(isValueParam, 0, sym); // true
__traits(isTypeParam, 1, sym); // true
__traits(isVariadicParam, 2, sym); // true
}
void X(int val, Type, Args...)(Args t) { return 0; }
B!(X);
And then you could wrap all of this into a Phobos template which collects all
the data. let's call it TemplateInfo:
template B(alias sym)
{
alias ti = TemplateInfo!sym;
static assert(ti.params.count == 2);
static assert(ti.params[0].isValueParam);
}
void X(Type, int val)() { }
B!(X);
That sort of stuff.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list