[Issue 13903] std.array.removeIf for associative arrays
https://issues.dlang.org/show_bug.cgi?id=13903 Iain Buclaw changed: What|Removed |Added Priority|P1 |P4 --
[Issue 13903] std.array.removeIf for associative arrays
https://issues.dlang.org/show_bug.cgi?id=13903 --- Comment #3 from Steven Schveighoffer --- I think especially if you remove the CURRENT element while iterating you are in for trouble. --
[Issue 13903] std.array.removeIf for associative arrays
https://issues.dlang.org/show_bug.cgi?id=13903 Steven Schveighoffer changed: What|Removed |Added CC||schvei...@yahoo.com --- Comment #2 from Steven Schveighoffer --- (In reply to Seb from comment #1) > auto removeIf(alias pred, AA)(AA aa) > { > aa.byPair.filter!(not!pred).each!(e => aa.remove(e.key)); > return aa; > } This implementation isn't valid. You can't remove while iterating. You would need to somehow lock the AA from rehashing as you removed items. --
[Issue 13903] std.array.removeIf for associative arrays
https://issues.dlang.org/show_bug.cgi?id=13903 Seb changed: What|Removed |Added CC||greensunn...@gmail.com --- Comment #1 from Seb --- Not sure whether such one/two-liners would be accepted to Phobos. --- import std.experimental.all; auto removeIf(alias pred, AA)(AA aa) { aa.byPair.filter!(not!pred).each!(e => aa.remove(e.key)); return aa; } void main() { auto aa = ["a" : 1, "b" : 2]; aa.removeIf!(a => a.key == "a").writeln; } --- But efficiency and bug-proneness are two good points. --