J
Jorgen Grahn
Around here, March--April is apple tree pruning time. I have a slighly
different problem:
I have a std::map<K, T> where I want to move all T (or pair<K, T>)
which match some predicate Pred to some other container. The map may
have a size in the millions, and Pred often matches all, or 50%, or
10% or so of the elements.
I'd prefer to use a standard algorithm for this, rather than iterating
manually, dealing with iterator invalidation and so on. Avoiding
repeated tree rebalancing would be welcome, but I suspect it's not
possible.
What's a good std algorithm for this? I guess std::remove_if() doesn't
work on maps -- since you cannot reorder the elements.
Since T is a pointer type in my case, I have some other options. I can
build a new map with only the !Pred elements in it, swap it with the
original, and blow away the original. Not sure that I would gain
performance from that (even more rebalancing?) but at least the code
would be clean ...
/Jorgen
different problem:
I have a std::map<K, T> where I want to move all T (or pair<K, T>)
which match some predicate Pred to some other container. The map may
have a size in the millions, and Pred often matches all, or 50%, or
10% or so of the elements.
I'd prefer to use a standard algorithm for this, rather than iterating
manually, dealing with iterator invalidation and so on. Avoiding
repeated tree rebalancing would be welcome, but I suspect it's not
possible.
What's a good std algorithm for this? I guess std::remove_if() doesn't
work on maps -- since you cannot reorder the elements.
Since T is a pointer type in my case, I have some other options. I can
build a new map with only the !Pred elements in it, swap it with the
original, and blow away the original. Not sure that I would gain
performance from that (even more rebalancing?) but at least the code
would be clean ...
/Jorgen