www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9608] New: Add introspection for templates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9608

           Summary: Add introspection for templates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrei erdani.com



PST ---
Currently given a template symbol it's not possible to do simple introspection
on it, such as getting arity, distinguishing alias vs. type parameters, and
figuring out variadics.

Example:

    template A(alias sym)
    {
        ...
    }
    A!((a, b) => a.name < b.name);

A is unable to tell the number of parameters of the lambda. It could if it knew
what type to instantiate it, and in order to know that it needs the actual
instantiation type. There should be enough introspection chops to compute the
number of parameters without instantiating the lambda.

There would be a fair amount of design involved because currently there's no
kind that expresses a template's parameters outside the template.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9608


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



15:16:48 PST ---
Is Issue 4265 relevant in any way (does it help?)?

I think I almost have a pull ready for Issue 4265, but it depends on whether
people really want the feature.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9608




11:32:36 PDT ---

 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: -------
Mar 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9608




PDT ---
Yah, issue 4265 is related. For this one, the challenge is defining a minimal
and complete set of traits.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2013