Livejournal
Log in
Post
Friends
My journal
the_real_crispy
Oh STL::list, why doth thou mock me so
May 05, 2007 22:01
MS implements them as circular linked lists, so ++(list.end()) == list.begin().
Quite unexpected. Sigh....
Leave a comment
Comments 2
zanate
May 7 2007, 13:03:10 UTC
jesus wept! You got a doc reference on that, or is this just observed behaviour?
Reply
the_real_crispy
May 7 2007, 16:45:40 UTC
Observed. The C++ standard is vague on this particular point (so it's implementation specific). So at least with VC++ 2003, you can see this kind of goodness:
std::list listObject;
std::list::const_iterator iter1 = listObject.begin();
listObject.push_back(1);
listObject.push_back(2);
listObject.push_back(3);
listObject.push_back(4);
listObject.push_back(5);
std::advance(iter1, 5);
std::list::difference_type nOffset = std::distance(listObject.begin(), iter1);
nOffset will equal 4. Also confirmed by using the debugger.
Reply
Leave a comment
Up
Comments 2
Reply
std::list listObject;
std::list::const_iterator iter1 = listObject.begin();
listObject.push_back(1);
listObject.push_back(2);
listObject.push_back(3);
listObject.push_back(4);
listObject.push_back(5);
std::advance(iter1, 5);
std::list::difference_type nOffset = std::distance(listObject.begin(), iter1);
nOffset will equal 4. Also confirmed by using the debugger.
Reply
Leave a comment