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.)
25.3.8 in the N3290 speaks about remove function :
and
This means that it depends on your predicate operator. Since your predicate doesn’t create a copy, then the elements are not going to be copied.