www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12421] New: Allow simpler syntax for lambda template declarations

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

           Summary: Allow simpler syntax for lambda template declarations
           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



03:23:28 PDT ---
-----
void main()
{
    import std.algorithm;
    import std.traits;

    {
        static auto notEmpty(Arr)(Arr arr) { return !arr.filter!(a => a >
0.0).empty; }
        assert(notEmpty([0.0, 0.0, 0.1]));
    }

    {
        // simpler syntax should be supported
        alias notEmpty = a => a.filter!(b => b > 0.0).empty;
        assert(notEmpty([0.0, 0.0, 0.1]));
    }
}
-----

Note how much code has to be written for a "throwaway" inline function
definition in the first case. This could be simplified by supporting the second
syntax.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 20 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12421




03:24:24 PDT ---
A slightly more fair comparison if we take into account that 'static' acts as
'auto':

-----
void main()
{
    import std.algorithm;
    import std.traits;

    {
        static notEmpty(A)(A a) { return !a.filter!(b => b > 0.0).empty; }
        assert(notEmpty([0.0, 0.0, 0.1]));
    }

    {
        // simpler syntax should be supported
        alias notEmpty = a => a.filter!(b => b > 0.0).empty;
        assert(notEmpty([0.0, 0.0, 0.1]));
    }
}
-----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 20 2014