February 16, 2012 [dmd-internals] Type inference for delegates/lambdas as regular parameters? | ||||
---|---|---|---|---|
| ||||
Hi, Consider this code: bool contains(T)(T[] arr, scope bool delegate(T) dg) in { assert(dg); } body { foreach (i; arr) if (dg(i)) return true; return false; } import std.stdio; void main() { writeln(contains([1, 2, 3], x => x == 2)); } This doesn't compile with 2.058; the type of x in the lambda expression cannot be deduced. Specifying the type explicitly works fine. This works: bool contains(alias dg, T)(T[] arr) { foreach (i; arr) if (dg(i)) return true; return false; } import std.stdio; void main() { writeln(contains!(x => x == 2)([1, 2, 3])); } Wasn't there supposed to be type inference for delegates passed as regular parameters in 2.058? Regards, Alex |
Copyright © 1999-2021 by the D Language Foundation