8 Jan
2010
8 Jan
'10
2:40 a.m.
"Dmitry Vinogradov"
To be short: it's not necessary.
BTW, begin() and end() for an empty list are valid. You can't dereference them, but they are valid. So one can use them for comparison. And BOOST_FOREACH does.
I've had problems with standard 'for' loops when using empty containers: for (i = mylist.begin() ; i != mylist.end() ; i++) By problems I mean core-dumps, memory leaks, etc. These problems went away when I used a size check: if (!mylist.empty()) for (i = mylist.begin() ; i != mylist.end() ; i++) This leads me to believe that begin() and end() are not valid, or is there another way to explain this?