Why can two std::vector iterators not be summed?
Iterators are modelled after pointers.
Given pointers P1
and P2
, the expression P2 - P1
gives you the offset/distance between the pointers. There is nothing sensible you can expect from the expression P1 + P2
.
Extend that idea to iterators and you will understand why subtraction between two iterators makes sense but addition does not.
because it makes not much sense to do that operation, therefore there is no operator+
defined in the iterator