Sunday, December 4, 2011

Random access iterator

random access iterator c++

Random access iterators have all the properties of bidirectional iterators. In addition, they can perform random access. In particular, they provide operators for "iterator arithmetic" (in accordance with "pointer arithmetic" of an ordinary pointer). You can add and subtract offsets, process differences, and compare iterators by using relational operators such as < and >. The iterators of the container.

Random-access iterator category
Bidirectional iterators are iterators especially designed for having the same functionality as standard pointers. Pointers are random access iterators.

Random access iterators are the most complete iterators in terms of functionality. They have the following characteristics: 

valid expressions
Can be default-constructed
X a;
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)
Can be incremented and decremented (when not null)
Supports arithmetic operators + and - between an iterator and an integer value, or subtracting an iterator from another
a + n
n + a
a - n
a – b
Supports inequality comparisons (<, >, <= and >=) between iterators
a < b
a > b
a <= b
a >= b
Supports compound assinment operations += and -=
a += n
a -= n
Supports offset dereference operator ([])

See Also:

No comments:

Post a Comment