www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10890] New: To find all arguments of an instantiated template

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

           Summary: To find all arguments of an instantiated template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2013-08-25 09:56:55 PDT ---
Given an instantiated template like:

struct Foo(T, U, size_t n) {}
alias F1 = Foo!(int, float, 5);

In many situations for me it's going to be useful a built-in trait (or a Phobos
template with the same semantics) that returns a TypeTuple of the original
template plus all the arguments used to instantiate it:

__trait(templateArguments, F1) ==> TypeTuple!(Foo, int, float, 5)

That means something like this should work:

alias TT = __trait(templateArguments, F1);
static assert(is(F1 == T[0]!(TT[1 .. $][])));

It should work with variadic templates too.

I have tagged this as dmd enhancement, but if a full library implementation is
possible, then this is meant just as a Phobos enhancement.

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


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #1 from hsteoh quickfur.ath.cx 2013-08-25 14:13:51 PDT ---
One workaround is to define a public alias inside your struct:

struct Foo(T...) {
    alias TemplateArgs = T;
    ...
}

alias F1 = Foo!(int, float, 5);
alias F1_parms = F1.TemplateArgs;

It's not as pretty, but it works.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-25
15:57:08 PDT ---
*** This issue has been marked as a duplicate of issue 4265 ***

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