www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get max elemenr over RegexMatch

reply Andrey <saasecondbox yandex.ru> writes:
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.
Aug 24 2018
parent ag0aep6g <anonymous example.com> writes:
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"()
Aug 24 2018