digitalmars.D.learn - Cannot use UFCS in lambda?
- berni (5/31) Sep 16 2018 When I replace the UFCS-Syntax in the lambda by a function call
- Vladimir Panteleev (6/7) Sep 16 2018 Lambdas are not the issue here. The problem is more general: you
- berni (1/6) Sep 16 2018 Good to know. :-)
- Paul Backus (2/9) Sep 16 2018 Worth noting, this is now included in Phobos as `std.meta.Alias`.
The following program does not compile:import std.stdio; import std.algorithm; struct A { struct S { int x; } const bool foo(in S s, in int k) { return s.x<k; } void bar() { [S(1),S(2),S(3),S(4),S(5)].filter!(a=>a.foo(3)).writeln; } } void main() { A().bar(); }I get (using rdmd):test.d(18): Error: no property foo for type S /usr/include/dmd/phobos/std/algorithm/iteration.d(1108): instantiated from here: >FilterResult!(__lambda1, S[]) test.d(18): instantiated from here: filter!(S[])When I replace the UFCS-Syntax in the lambda by a function call it works:[S(1),S(2),S(3),S(4),S(5)].filter!(a=>foo(a,3)).writeln;Where is my mistake?
Sep 16 2018
On Sunday, 16 September 2018 at 09:46:15 UTC, berni wrote:Where is my mistake?Lambdas are not the issue here. The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the page).
Sep 16 2018
The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the page).Good to know. :-)
Sep 16 2018
On Sunday, 16 September 2018 at 10:55:43 UTC, berni wrote:Worth noting, this is now included in Phobos as `std.meta.Alias`.The problem is more general: you can only use top-level symbols in UFCS. You can use an identity alias template to bypass this: https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/ (search for UFCS in the page).Good to know. :-)
Sep 16 2018