[Issue 22501] New: Improve lambda inference for delegate type template params
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 10 15:07:28 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22501
Issue ID: 22501
Summary: Improve lambda inference for delegate type template
params
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: kinke at gmx.net
This currently works, templatizing the delegate type for attribute propagation
while still documenting the expected signature:
```
size_t count(T, P : bool delegate(T))(T[] array, P predicate) {
size_t ret;
foreach (e; array)
if (predicate(e))
++ret;
return ret;
}
size_t countOdd(int[] array) @nogc nothrow pure @safe {
return array.count(delegate(int a) => a % 2 == 1);
}
```
But the usage is plain ugly and super-explicit. Inferring parameter types and
promoting the function literal to a delegate literal would be a very welcome
improvement and enable `array.count(a => a % 2 == 1)`.
--
More information about the Digitalmars-d-bugs
mailing list