I have a situation. I have used a templated function for one of my task. To this function, I pass iterator by reference. Now, I have to delete few elements from a vector. How do I do this using only iterators? Pl find the respective code:
template <class BidirectionalIterator, class Iterator> bool
SomeFunc( BidirectionalIterator& first, BidirectionalIterator& last, Iterator anotherVecBegin )
{
while((first+1) != last)
{
if(some_condition)
// delete (first); HOW?
else if(some_other_condition)
// delete (first + 1); HOW?
}
// add something to another vector using anotherVecBegin
return true;
}
There are many already asked questions, but they all have a vector in context. so myVec.erase(*first)
is easy..
I am also aware that its not a very good way that I pass iterator by reference. But I am following simple rules: use references when something is expected to be changed or to avoid heavy copy. My scenario is fitting first condition.
So How do I delete?