tags:

views:

59

answers:

1

In C++ primer 4th edition by Lippman, compound assignment operators for iterator for vector and deque are given :

iter1 += iter2 
iter1 -= iter2

Compound-assignment versions of iterator addition and subtraction. Assigns the value of adding or subtracting iter1 and iter2 into iter1.

But when I want to use them, it gives error. Moreover what does it mean to provide compound assignment operators for iterators anyway?

+2  A: 

I looked this up in Lippman. To me it looks like an error. Random access iterators (the kind of iterator provided by vector and deque) offer compound assign of the form

iter += n
iter -= n

See e.g. http://www.cplusplus.com/reference/std/iterator/RandomAccessIterator/

Compound assignment of the form Lippman wrote doesn't make sense when you look at the resulting types.

Peter G.