Get max elemenr over RegexMatch

Andrey saasecondbox at yandex.ru
Fri Aug 24 11:13:52 UTC 2018


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.


More information about the Digitalmars-d-learn mailing list