Re: Should I derive my iterator from std::iterator, on VC++ 2005?
On Tue, 16 Jan 2007 23:16:11 +0100, "Niels Dekker - no return address"
<unknown@this.is.invalid> wrote:
I recently wrote an iterator, and derived it from std::iterator, to make
it compliant with the STL algorithms. Now I expected std::iterator to
only contain a few typedefs, but the VC++ 2005 version contains a lot
more! Depending on some compiler settings, it might have 64 bits of
data, and a few member functions, provided by its base class,
_Iterator_base.
Do you have any suggestions on how to make use of those additional
members of std::iterator, for the implementation of my own iterator?
I think the extras come into play automatically when you compile with
_SECURE_SCL, _HAS_ITERATOR_DEBUGGING, etc.
Or should I just stay away from _Iterator_base? If so, is it still
recommended to derive my own iterator from std::iterator? Because I
find the memory overhead quite large, compared to the size of my
iterator!
There's nothing requiring you to derive from std::iterator, so if you want
to minimize the space requirement (realizing you're sacrificing security
and debugging features), you can just define your own typedefs in your
iterator classes if you want. That said, unless you're storing a lot of
iterators in some data structure, I wouldn't worry about the size overhead.
Also, you can add /D_SECURE_SCL=0 to your command line or use the
corresponding #define, and that will cut out the extra members, so, for
example, sizeof(vector::iterator) goes from 8 in a release build to 4. But
that's kind of a blunt tool.
--
Doug Harrison
Visual C++ MVP