c++ - Checking if an iterator is valid -


is there way check if iterator (whether vector, list, deque...) (still) dereferencable, i.e. has not been invalidated?

i have been using try-catch, there more direct way this?

example: (which doesn't work)

list<int> l; (i = 1; i<10; i++) {     l.push_back(i * 10); }  itd = l.begin(); itd++; if (something) {     l.erase(itd); }  /* now, in other place.. check if itd points somewhere meaningful */ if (itd != l.end()) {     //  blablabla } 

i assume mean "is iterator valid," hasn't been invalidated due changes container (e.g., inserting/erasing to/from vector). in case, no, cannot determine if iterator (safely) dereferencable.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -