August 24, 2018 Get max elemenr over RegexMatch | ||||
---|---|---|---|---|
| ||||
Hello, This code produces an error: >auto matches = content.matchAll(pattern); >auto max = matches.maxElement!"a => a.back.to!uint"(); I have a RegexMatch array like: >[["text1234", "1234"], ["zxs432fff", "432"], ["text000_eeee", "000"]] Max element here is 1234. I apply map function "a => a.back.to!uint" to each Capture -> take last hit, convert it to uint and return for comparison. But compiler says: >template std.algorithm.searching.extremum cannot deduce function from argument types !("a => a.back.to!uint", "a > b")(RegexMatch!(char[])), candidates are: I can't understand what it wrong here. This works: > matches.map!(a => a.back.to!uint)().maxElement() I don't want to use this variant because, as I understand, here we create a temporary uint array and then search for max element. I.e. there is an unnecessary allocation of memory. |
August 24, 2018 Re: Get max elemenr over RegexMatch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrey | On 08/24/2018 01:13 PM, Andrey wrote: > This code produces an error: >> auto matches = content.matchAll(pattern); >> auto max = matches.maxElement!"a => a.back.to!uint"(); You're mixing two different notations. It's either matches.maxElement!(a => a.back.to!uint)() or matches.maxElement!"a.back.to!uint"() |
Copyright © 1999-2021 by the D Language Foundation