Bug 12421 – Allow simpler syntax for lambda template declarations
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-20T03:23:00Z
Last change time
2016-01-03T14:20:07Z
Keywords
pull
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2014-03-20T03:23:28Z
-----
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.
Comment #1 by andrej.mitrovich — 2014-03-20T03:24:24Z
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]));
}
}
-----