Boost logo

Boost Users :

From: LoadCom (LoadCom_at_[hidden])
Date: 2007-11-02 03:54:24


Hello,

It's a question that perhaps has little to do with boost, but I
guess the boosters must be able to help me. :-)

The question is: I want to have an iterator of a std::list type
that denotes a NULL iterator, which means the iterator points to
nothing, and is obviously different from list::end(), which points
to the pass-the-end of a list.

I'm using the following code:

list<int> alist;
alist.push_back(1);

list<int>::iterator it_NULL; // denotes a NULL iterator
list<int>::iterator it_beg = alist.begin();

std::cout << boolalpha;
std::cout << "(it_NULL == it_beg) " << (it_NULL == it_beg) << endl;

I got correct result under VS 2003, but under VS2005, I got an
runtime error. The cause of the error seems to be I could not compare
2 iterators that don't belong to the same container.

I have looked up the C++ 98 standard, and there seems not to be such a
restriction for 2 iterators of the same type in comparasion should
belong to a same container.

What's wrong? Or any other alternative solution available?
Thanks in advance for any help.

Max


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net