Michael D. Berger wrote:
> Is std::vector arithmetic allowed? For example:
>
> std::vector<unsigned> vec;
>
> ... // put things in vec .
>
> vec.erase(vec.begin(),vec.begin()+2);
>
> erases first two item in vec . OK?
>
> Chapter & verse?
>
Yes, the iterators are "random access iterators" which allows adding
or subtracting from them.
Other containers have other kinds of iterators, and the compiler will
tell you when addition doesn't work. One example is std::list, whose
iterators can be incremented and decremented, but not added to.
Bo Persson
|