In the following loop I'm using a pre-calculated end iterator:
std::list::iterator end = MyList.end(); for (std::list::iterator it = MyList.begin(); it != end ;) it = MyList.erase(it); When erasing an element in a std::list, can the MyList.end() change its value so that end != MyList.end() anymore?
std::list. One should read each container's documentation for the specifics of what invalidation guarantees it does or does not offer.end(), it only works for some containers, so don't get into the habit.