Topic: STL: Non-initialized iterators
Author: "Dietmar May" <dmay@infoave.net>
Date: 1996/11/27 Raw View
Is there a (valid) reason why the default ctors for list<...>::iterator and
map<...>::iterator do not initialize the object to a default value? The
node pointers in deque<...>::iterator do get initialized. Thus, it is
possible to do this:
deque<...>::iterator iter;
if(iter == deque<...>::iterator())
;
but not this:
list<...>::iterator iter;
if(iter == list<...>::iterator())
;
because the list node pointers are uninitialized.
The problem can be circumnavigated for lists by:
template <...> class List<...> : public list<...>
{
public:
static iterator get_nil_iterator() { return iterator(0); }
};
since iterator::iterator(link_type) is protected. However, this fails for
maps since the iterator is a member of an enclosed class.
Does anyone know if the ANSI spec explicitly requires or disallows default
initialization for iterators? In other words, can I be guaranteed that two
default constructed iterators are equal in value (or more precicely, that
their equality can be reliably ascertained using the equality operator ==)?
If not, is there any portable way to perform this?
Thanks,
Dietmar
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]