Kai-Uwe Bux a écrit :
Juha said:
Why would your version make any difference?
[snip] code
If you had an implementation of std::vector<> that uses pointers to
implement iterators, you would run into similar problems.
I agree with you, this is buggy behavior.
Just not to be misleading about iterator being pointer, such an
implementation would lack iterator traits.
A minimal Input iterator would be:
struct iterator
{
//traits
typedef T value_type;
typedef ptrdiff_t distance_type;
//etc
//actual pointer
T* pointer;
//constructor
iterator(T* def=NULL)

ointer(def){}
//assignment operator
iterator operator=(const iterator& it)
{
this->pointer=it.pointer;
return *this;
}
//equality/inequality operator
bool operator==(const iterator& it){return this->pointer==it.pointer;}
bool operator!=(const iterator& it){return this->pointer!=it.pointer;}
//dereference operator
T operator*(){return *(this->pointer);}
//pre/post increment operator
iterator operator++(){++this->pointer;return *this;}
iterator operator++(int){iterator
old(this->pointer);++this->pointer;return old;}
iterator operator--(){--this->pointer;return *this;}
iterator operator--(int){iterator
old(this->pointer);--this->pointer;return old;}
};
And in this case, the example you gave do compile.
Michael.