Sunday, December 4, 2011

Bidirectional iterator

Bidirectional iterator in c++

As the name indicates, bidirectional iterators are able to iterate in two directions: forward, by using the increment operator, and  backward, by using the decrement operator. The iterators of the container classes list, set, multiset, map, and multimap are bidirectional iterators.

Bidirectional iterator category

Bidirectional iterators are iterators especially designed for sequential access in both directions - towards the end and towards the beginning.

They have the following characteristics:

Characteristic
valid expressions
Can be default-constructed
X a;
X()
Can be copied and copy-constructed
X b(a);
b = a;
Accepts equality/inequality comparisons.
Equal iterators imply the same element is pointed
a == b
a != b
Can be dereferenced (when not null)
*a
a->m
Can be incremented (when not null)
++a
a++
*a++
Can be decremented (when not null)
--a
a--
*a--

See Also:


No comments:

Post a Comment