參考資料:
- http://www.mip.ups-tlse.fr/~grundman/stl-tutorial/tutorial.html
Why doesn't STL have null iterator values? STL iterators are supposed to be generalized pointers, right? That phrase has been bandied about a great deal, but it is very misleading. STL iterators are generalizations of array pointers, that is, a pointer set to point into an array, and then incremented or decremented. It does not make sense to talk about such a pointer having a null value.
In C and C++, null pointers are used to indicate errors, or abnormal conditions. When you have a C++ iterator type, there is normally only one kind of error value it will return: one indicating "I fell off the end of the list". It is natural, therefore, for most iterator classes to use null as the "past-the-end" value. If you find yourself wanting a null STL iterator, you probably want the past-the-end value.