Bug 22501 – Improve lambda inference for delegate type template params

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-11-10T15:07:28Z
Last change time
2024-12-13T19:19:17Z
Assigned to
No Owner
Creator
kinke
See also
https://issues.dlang.org/show_bug.cgi?id=8131
Moved to GitHub: dmd#20007 →

Comments

Comment #0 by kinke — 2021-11-10T15:07:28Z
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)`.
Comment #1 by robert.schadek — 2024-12-13T19:19:17Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20007 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB