www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6081] New: Function Literal Templates Don't Work when Nested in Templates

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

           Summary: Function Literal Templates Don't Work when Nested in
                    Templates
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: wfunction hotmail.com



The following piece of code, which finds the length of the longest line in a
file,

    pipe!(readText, splitlines, map!((a) { return a.length; }),
reduce!max)("Temp.d");

fails with:

    Error: expression template map(Range) if (isInputRange!(Unqual!(Range))) is
not a valid template value argument



If you try to get around it by saying

    pipe!(readText, splitlines, map!(delegate size_t(string a) { return
a.length; }), reduce!max)("Temp.d");

you then get:

    Error: delegate std.algorithm.__dgliteral1 cannot access frame of function
Temp.main.__dgliteral1

and saying "function" instead of "delegate" doesn't change anything.


You can get around it with using a string instead of a function literal as the
template argument, but that still doesn't really solve the issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6081




Well, sorry: if you say "function" instead of "delegate", the error _does_
change... it becomes:

    Error: delegate std.algorithm.__dgliteral1 cannot access frame of function
Temp.main.__dgliteral1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6081





 Well, sorry: if you say "function" instead of "delegate", the error _does_
 change... it becomes:
 
     Error: delegate std.algorithm.__dgliteral1 cannot access frame of function
 Temp.main.__dgliteral1
Whoops, major apologies for the typo and 2nd comment... should've been: Error: function std.algorithm.__funcliteral1 cannot access frame of function Temp.main.__funcliteral1 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 31 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6081


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |hsteoh quickfur.ath.cx
         Resolution|                            |WORKSFORME



It would be helpful if code snippets include full compilable code. Anyway,
based on the bug description, I constructed the following test case:

----
import std.algorithm, std.file, std.functional, std.string;
void main() {
    pipe!(readText, splitLines, map!((a) { return a.length; }),
    reduce!max)("Temp.d");
}
----

This code compiles correctly in dmd git HEAD (6a90c4df), so it appears that it
has been fixed.

Please reopen this bug if you still encounter problems. Thanks!

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