I am using the erase-remove idiom:
template <typename T>
bool garbageCollectVector(std::vector<T>& v) {
// Use the erase-remove idiom in combination with a lambda expression
v.erase(
std::remove_if(v.begin(), v.end(),
[this](const T& elem) -> bool {
return this->shouldRemove(elem);
}
),
v.end());
return /* what to return? */;
}
and want to return whether the method actually removed any element or not. What is the cleanest way to do that?
Alternatively to the size check, you may split your implementation: