Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::list and iterators validity

12 views
Skip to first unread message

Noir

unread,
Aug 17, 2010, 8:46:50 AM8/17/10
to
Hello,
I have a couple of related question about the validity of list
iterators. I am embedding the questions in the code:

--------------------------------
std::list<int> l;
std::list<int>::iterator it1 = l.insert(l.end(), 1);
std::list<int>::iterator it2 = l.insert(l.end(), 2);
std::list<int>::iterator it3 = l.end();

l.clear();

// it1, it2 are now invalid.
// *** QUESTION 1: is it3 invalid now?

// *** QUESTION 2: is l.end() below the same as l.end() when
// it3 was first initialized?

if (it3 == l.end())
std::cout << "Unassigned\n";
--------------------------------

Thank you

Leigh Johnston

unread,
Aug 17, 2010, 8:56:21 AM8/17/10
to

"Noir" <no...@invalid.com> wrote in message
news:4c6a84bc$0$12127$4faf...@reader4.news.tin.it...

"No *other* iterators, pointers, or references are invalidated when
inserting or erasing any items.", so an end() iterator is not invalidated
after calling clear().

/Leigh

0 new messages