Given an std::vector<std::unique_ptr<SomeType> >, is it legal to use remove_if on it? In other words, given this code:
std::vector<std::unique_ptr<SomeType> > v; // fill v, all entries point to a valid instance of SomeType... v.erase( std::remove_if( v.begin(), v.end(), someCondition ), v.end() ); , am I guaranteed after the erase that all pointers still in v are valid. I know that given the intuitive implementation of std::remove_if, and given all of the implementations I've looked at, they will be. I'd like to know if there is anything in the standard which guarantees it; i.e. that std::remove_if is not allowed to copy any of the valid entries without recopying the copy into its final location.
(I am, of course, supposing that the condition doesn't copy. If the condition has a signature like:
struct Condition { bool operator()( std::unique_ptr<SomeType> ptr ) const; }; , then of course, all of the pointers will be invalid after remove_if.)
unique_ptris not copy constructible, so if you used that predicate your code wouldn't compile.std::uniqueis not copyable but movable. It can be moved to the end of container.auto_ptrbut notunique_ptr(the code simply wouldn't compile).