This is the mail archive of the mailing list for the libstdc++ project. See the libstdc++ home page for more information.

[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]


Kevin Atkinson wrote:
> >-  fix vector and string to define non-pointer iterator types.  Pointers
> >   as container iterators are evil.
> Could someone explain why this is?

I am not entirely sure, but I suspect it is because you do not have
control over what the increment, decrement, dereference, etc. operators
do - you depend upon the pointer semantics. Instead, these should be
defined specifically for each container class. This is certainly
necessary for things like reverse_iterator, where the normal
increment/decrement operations are reversed. Pointers only work in the
trivial case as iterators. Even though late standards changes made sure
that you could treat iterators LIKE pointers (ie. by using -> on them)
they were never intended to BE pointers.

Someone may have some more concrete reasons why pointers are truly evil,
and not simply a hack until a proper implementation was completed. I
could be entirely wrong here.