STL defect?

Thomas Kunert kunert@physik.tu-dresden.de
Wed Sep 2 02:35:00 GMT 1998


nbecker wrote:
> 
> This small test program demonstrates either a defect in STL design or
> in egcs implementation.
> 
> -----------------
> #include <vector>
> #include <deque>
> 
> main () {
>   vector<double> V;
>   deque<double> D;
>   vector<double>::iterator I;
>   deque<double>::iterator J;
>   double* p1 = J.operator->();
>   double* p2 = I.operator->();
> }
> 
> ---------------
> g++ -c Test.cc
> Test.cc: In function `int main()':
> Test.cc:10: request for member `operator ->' in `I', which is of non-aggregate type `double *'
> 
> 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->.

What do you mean by `STL says' ?
The standard doesn't require that and, IIRC, has never done.
It just says, that `I->x' is equivalent to `(*I).x' *if the latter is
well-defined*.

You can rewrite the above expression:

double* p1 = &(*J);
double* p2 = &(*I);

--
Thomas Kunert



More information about the Gcc mailing list