This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: STL defect?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]