This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: STL defect?
- To: "'egcs at cygnus dot com'" <egcs at cygnus dot com>, "'nbecker at fred dot net'" <nbecker at fred dot net>
- Subject: Re: STL defect?
- From: "Kühl, Dietmar" <Dietmar dot Kuehl at IZB-SOFT dot de>
- Date: Wed, 2 Sep 1998 15:24:40 +0200
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...