"P.J. Plauger" <pjp@plauger.com> wrote
Why not create an empty list and use begin() or end() from that
(otherwise unused) list as your invalid iterator?
Dani wrote:
Because "bool" will cost me less... :-D
Maybe, depending on how your program is organized.  You could have a 
single global empty list whose end iterator is, by convention, your 
universal "this iterator doesn't point to anything" value.  If you want 
to use "bool" to indicate the validity of an iterator, then it seems like 
you would need a bool variable for each and every iterator object. The 
memory cost of the bool solution seems like it would be a lot higher than 
the empty list solution.  As for the more important code complexity cost, 
I would think the empty list would win again, because it behaves almost 
exactly like a null pointer (which everybody is very familiar with), the 
only real difference being that it has a name other than NULL.