How to check if the iterator is initialized?

Viewed 30001

If I use a default constructor for an iterator, how to check if it was assigned later on?

For pointers, I could do this :

int *p = NULL;
/// some code
if ( NULL == p ) {
  // do stuff
}

How do I do the above for iterators? Is it possible at all?

#include <iostream>
#include <list>

int main ()
{
    std::list<int>::iterator it;

  if ( NULL == it ) // this fails
  {
      std::cout<<"do stuff" << std::endl;
  }
}
11 Answers
Related