Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
C++ How to Program, 5/e

ISBN:
0-13-185757-6
© 2005
pages: 1500
Buy the Book!
Amazon logo
InformIT logo

[Note: This tutorial is an excerpt (Sections 23.1) of Chapter 23, Standard Template Library (STL), from our textbook C++ How to Program, 5/e. These tutorials may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., C++ HOW TO PROGRAM, ©2005, pp.1112-1123. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]

 

23.1.2 Introduction to Iterators (Continued)

Iterator Operations

Figure 23.10 shows some operations that can be performed on each iterator type. Note that the operations for each iterator type include all operations preceding that type in the figure. Note also that, for input iterators and output iterators, it is not possible to save the iterator and then use the saved value later.
 

Iterator operation Description
All iterators
++p Preincrement an iterator.
p++ Postincrement an iterator.
Input iterators
*p Dereference an iterator.
p = p1 Assign one iterator to another.
p == p1 Compare iterators for equality.
p != p1 Compare iterators for inequality.
Output iterators
*p Dereference an iterator.
p = p1 Assign one iterator to another.
Forward iterators Forward iterators provide all the functionality of both input iterators and output iterators.
Bidirectional iterators
--p Predecrement an iterator.
p-- Postdecrement an iterator.
Random-access iterators
p += i Increment the iterator p by i positions.
p -= i Decrement the iterator p by i positions.
p + i Expression value is an iterator positioned at p incremented by i positions.
p - i Expression value is an iterator positioned at p decremented by i positions.
p[ i ] Return a reference to the element offset from p by i positions
p < p1 Return true if iterator p is less than iterator p1 (i.e., iterator p is before iterator p1 in the container); otherwise, return false.
p <= p1 Return true if iterator p is less than or equal to iterator p1 (i.e., iterator p is before iterator p1 or at the same location as iterator p1 in the container); otherwise, return false.
p > p1 Return true if iterator p is greater than iterator p1 (i.e., iterator p is after iterator p1 in the container); otherwise, return false.
p >= p1 Return true if iterator p is greater than or equal to iterator p1 (i.e., iterator p is after iterator p1 or at the same location as iterator p1 in the container); otherwise, return false.

Fig. 23.10 Iterator operations for each type of iterator.

Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

Tutorial Index