You can do ++ by the return value of vector::begin() if it returns the value l - essentially the type of object that has an overloaded ++ operator . I do not think that the standard insists on how to implement vector::iterator . The corresponding C ++ standard library can implement vector::iterator as a pointer, that is, for vector<T> , vector<T>::iterator can be T* , in which case the ++ operation will not compile, because the return is value of r, and you cannot increase the value of r.
The C ++ library that you are using currently implements vector::iterator as an object with overloaded ++ and therefore it works. But this does not mean that it is tolerated.
Try this program
class iter { int * p_; public: iter(int * p):p_(p) {} iter & operator ++() { ++p_; return *this; } }; class A { int * p_; public: typedef int * iterator; typedef iter miterator; iterator get() { return p_; } miterator ret() { return miterator(p_); } }; int main(int argc, char **argv) { A a; ++a.get();
source share