I need a method to remove all elements fulfilling a certain criteria from a range (an std::vector
in this particular case) and copy those removed elements to a new range (so something like std::remove_if
with an output parameter.) Neither the order of the input range nor the order of the output range after this operation is relevant.
One naive approach would be using std::partition
to find all "evil" elements, then copy those and last remove them, but this would touch all the "evil" elements twice without need.
Alternatively I could write the desired remove_if
variant myself, but why reinvent the wheel (plus I do not know if I can match the efficiency of a high quality library implementation).
So the question is:
Does a such a function already exist? Boost is allowed, but standard C++ is preferred (the project does not depend on boost yet).
If not, is there a smart algorithm that is faster than a naive handcrafted remove_if
variant would be?