Reputation: 4282
I have an std::vector<IRenderable*>
(_pBkBuffer
in the code below). It contains a number of static objects (at the start of the vector) that don't change, followed by a variable number of dynamic objects.
// erase-remove, but leave the static renderables intact
_pBkBuffer->erase(
std::remove(
_pBkBuffer->begin() + _nStatics, _pBkBuffer->end(), ???
),
_pBkBuffer->end()
);
What can I put at the ??? in order to erase-remove the non-static renderables?
I know that the ??? should match all objects in the specified subset.
Should I be using erase-remove at all, or should I use another approach?
Upvotes: 2
Views: 317
Reputation: 55395
'Should I be using erase-remove at all
Aparently you already know where the object are, so no. You do this:
_pBkBuffer->erase( _pBkBuffer->begin() + _nStatics, _pBkBuffer->end() );
or, even better:
_pkBuffer->resize( _nStatics );
Erase remove idiom would be used if you had them scattered randomly in the vector. What's missing instead of ???
is a value that elements to be removed are compared to. Since you're storing pointers, you'd most likely need to provide a custom predicate (a function pointer, functor, or a lambda) and use remove_if
instead.
Upvotes: 4