Hello Dagon Thanks for your reply. I'm not using empty() because what I want to test is not the emptyness of a list, but that of an iterator. Or, in other words, I want to test if an iterator itself doesn't point to any object - that is different from the begin() or end() of a list. ------------------ Max 2007-11-05 ------------------------------------------------------------- 发件人:Benoi^t Dagon 发送日期:2007-11-02 16:34:12 收件人:boost-users@lists.boost.org 抄送: 主题:Re: [Boost-users] [STL] An question about list::iterator Hi, I'm not sure to understand the goal of your test iterator comparison but if it's to test a list emptiness why not just using alist.empty()? In my understanding a list iterator is not designed to be NULL. But the object it points to could be null and thus you should better test the object than the iterator. Hope it helps, ~Benoi^t LoadCom wrote:
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users