STL defect?

Kühl, Dietmar Dietmar.Kuehl@IZB-SOFT.de
Wed Sep 2 07:28:00 GMT 1998


Hi,

>This small test program demonstrates either a defect in STL design or
>in egcs implementation.

It is neither a defect in the STL design nor in the implementation.

>The problem is that the builtin pointer types don't implement operator->, so
>operator-> won't work for vector, whose underlying representation of
>an iterator is a pointer.  But STL says that iterators should have an
>operator->.

No, it does not say that iterators should have an 'operator->()'. Here
is what
it says (this is what is found in CD2 but I think the words on this have
not
changed in DIS):

  All iterators i for which the
  expression (*i).m is well-defined, support the  expression  i->m  with
  the  same  semantics  as  (*i).m.

(the quote is taken from lib.iterator.requirements paragraph 1). Note
that
it is *never* required that there has to be an 'operator->()' for an
iterator,
even not if '(*i).m' is well defined: The implementation can choose to
implement some special magic in this case which is different from
'operator->()' but implements 'i->m' with the same semantics as
'(*i).m'.
Actually, this is what happens if the iterator type is a pointer: In
this case
some special magic (the implicit 'operator->()' on pointer types) is
used.

The expression you tried to use is not at all required to be supported!
However, it is likely that all implementations use 'operator->()' for
iterators
which are not pointers...



More information about the Gcc mailing list