Yes; you can use erase / delete idioms with a special predicate:
template <typename SetT> struct not_contained_in_set_impl { not_contained_in_set_impl(const SetT& s) : set_(s) { } template <typename T> bool operator()(const T& v) { return set_.find(v) == set_.end(); } const SetT& set_; }; template <typename SetT> not_contained_in_set_impl<SetT> not_contained_in_set(const SetT& s) { return not_contained_in_set_impl<SetT>(s); }
Used as:
orders.erase( std::remove_if(orders.begin(), orders.end(), not_contained_in_set(erase_if_not_found)), orders.end());
[compiled in my head on the fly]
If you want to sort the range first, you have other options that might work better ( std::set_intersection , for example).
source share