std.algorithm for changing array values

Andre andre at s-e-a-p.de
Wed Jan 15 12:57:37 PST 2014


Am 15.01.2014 21:54, schrieb anonymous:
> If you want to stop after the first match:
>
> auto f = entries.find!(d => d.key == 3);
> if(f.empty) entries ~= Data(3,42);
> else f.front.value = 42;
>
> If there can be duplicates and you want to change them all:
>
> auto f = entries.filter!(d => d.key == 3);
> if(f.empty) entries ~= Data(3,42);
> else foreach(ref e; f) e.value = 42;

Fantastic!
Thanks a lot.

Kind regards
André


More information about the Digitalmars-d-learn mailing list