Possible Duplicate:
C++ Best way to check if an iterator is valid
Let's say I have a function which takes an iterator as its sole parameter as below.
void DoSomethingWithIterator(std::vector<int>::iterator iter)
{
// Check the pre-condition
assert( /* how to validate iter here? */ )
// Operate on iter afterwards
..
}
How do I know if iter
is valid or not. By valid, I mean it points to a existing element inside the vector, e.g., from m_intVector.begin()
to m_intVector.end()
.