www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9886] New: Cannot pass .tupleof directly to a template

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

           Summary: Cannot pass .tupleof directly to a template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



12:25:56 PDT ---
template Templ(T...) { alias Templ = T; }

struct S { int x, y; }

void main()
{
    S s;
    auto tup = s.tupleof;

    auto x = Templ!(tup);  // ok
    auto y = Templ!(s.tupleof);  // ng
}

For a use-case, a recently created 'reverse' function for the Phobos Tuple type
had this implementation:

 property
auto reversed()
{
    static if (is(typeof(this) : Tuple!A, A...))
        alias RevTypes = Reverse!A;

    Tuple!RevTypes result;
    auto tup = this.tupleof;  // can't call Reverse(this.tupleof) directly
    result.tupleof = Reverse!tup;
    return result;
}

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





 template Templ(T...) { alias Templ = T; }
 
 struct S { int x, y; }
 
 void main()
 {
     S s;
     auto tup = s.tupleof;
 
     auto x = Templ!(tup);  // ok
     auto y = Templ!(s.tupleof);  // ng
 }
This is disallowed by current language spec. `s.tupleof` makes a tuple of expressions (s.x, s.y). But template cannot take runtime evaluated expressions. So it would be rejected.
 For a use-case, a recently created 'reverse' function for the Phobos Tuple type
 had this implementation:
 
  property
 auto reversed()
 {
     static if (is(typeof(this) : Tuple!A, A...))
         alias RevTypes = Reverse!A;
 
     Tuple!RevTypes result;
     auto tup = this.tupleof;  // can't call Reverse(this.tupleof) directly
     result.tupleof = Reverse!tup;
     return result;
 }
In member function, template can take field variables as symbol. So this works. struct S { int x; string y; auto test() { auto t = Templ!(this.tupleof); // same as Templ!(x, y) pragma(msg, typeof(t)); // (string, int) } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9886


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



12:55:28 PDT ---
Yeah I guess it makes sense this would be disallowed, I wrongly interpreted
't.tupleof' to be a set of symbols.

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