digitalmars.D.learn - filtering a row of a jagged array
- DanielG (16/16) Aug 11 2019 int[][] whatever = [
- ag0aep6g (3/4) Aug 11 2019 You just forgot an exclamation mark here.
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (6/23) Aug 11 2019 You're missing an exclamation mark after filter - it takes the
- DanielG (5/5) Aug 11 2019 Thank you both! Ugh, I have to roll my eyes at missing such a
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/6) Aug 11 2019 You're not alone. We want this bug fixed:
int[][] whatever = [ [0], [0, 1, 2], [5, 6, 7, 8, 9, 10] ]; writeln(whatever[2]); // [5, 6, 7, 8, 9, 10] writeln(typeid(whatever[2])); // int[] auto x = whatever[2].filter(x => x > 7); // error Error: template std.algorithm.iteration.filter cannot deduce function from argument types !()(int[], void), candidates are: ... Online example: https://run.dlang.io/is/LUXFuF ... I'm guessing I need to give the compiler some help understanding that this is an array of ints, but 1) how, and 2) why? [if typeid() seems to understand just fine?]
Aug 11 2019
On 11.08.19 18:11, DanielG wrote:auto x = whatever[2].filter(x => x > 7); // errorYou just forgot an exclamation mark here. auto x = whatever[2].filter!(x => x > 7); // works
Aug 11 2019
On Sunday, 11 August 2019 at 16:11:15 UTC, DanielG wrote:int[][] whatever = [ [0], [0, 1, 2], [5, 6, 7, 8, 9, 10] ]; writeln(whatever[2]); // [5, 6, 7, 8, 9, 10] writeln(typeid(whatever[2])); // int[] auto x = whatever[2].filter(x => x > 7); // error Error: template std.algorithm.iteration.filter cannot deduce function from argument types !()(int[], void), candidates are: ... Online example: https://run.dlang.io/is/LUXFuF ... I'm guessing I need to give the compiler some help understanding that this is an array of ints, but 1) how, and 2) why? [if typeid() seems to understand just fine?]You're missing an exclamation mark after filter - it takes the predicate as a template argument. This compiles just fine: auto x = whatever[2].filter!(x => x > 7); -- Simen
Aug 11 2019
Thank you both! Ugh, I have to roll my eyes at missing such a simple error. (This literally occurred in the context of a bunch of other code using 'map' and 'reduce' with the exclamation point, so I don't know why my brain turned off for 'filter') Thanks again!
Aug 11 2019
On 08/11/2019 09:43 AM, DanielG wrote:such a simple errorYou're not alone. We want this bug fixed: https://issues.dlang.org/show_bug.cgi?id=17263 Ali
Aug 11 2019