C++ Iterator Library - random_access_iterator_tag



Description

It used to identify the category of an iterator and a random-access iterator support at least one of the following operations.

C++98

property valid expressions
It is a default-constructible, copy-constructible, copy-assignable and destructible

X a;

X b(a);

b = a;

It can be compared for equivalence using the equality/inequality operators

(meaningful when both iterator values iterate over the same underlying sequence).

a == b

a != b

It can be dereferenced as an rvalue (if in a dereferenceable state).

*a

a->m

For mutable iterators (non-constant iterators):

Can be dereferenced as an lvalue (if in a dereferenceable state).

*a = t

It can be incremented (if in a dereferenceable state).

The result is either also dereferenceable or a past-the-end iterator.

Two iterators that compare equal, keep comparing equal after being both increased.

++a

a++

*a++

It can be decremented (if a dereferenceable iterator value precedes it).

--a

a--

*a--

Supports the arithmetic operators + and - between an iterator and an integer value, or subtracting an iterator from another.

a + n

n + a

a - n

a - b

Can be compared with inequality relational operators (<, >, <= and >=).

a < b

a > b

a <= b

a >= b

Supports compound assignment operations += and -=

a += n

a -= n

Supports the offset dereference operator ([]) a[n]

C++11

property valid expressions
It is a default-constructible ,copy-constructible ,copy-assignable and destructible

X a;

X b(a);

b = a;

It can be compared for equivalence using the equality/inequality operators

(meaningful when both iterator values iterate over the same underlying sequence).

a == b

a != b

It can be dereferenced as an rvalue (if in a dereferenceable state).

*a

a->m

For mutable iterators (non-constant iterators):

Can be dereferenced as an lvalue (if in a dereferenceable state).

*a = t

It can be incremented (if in a dereferenceable state).

The result is either also dereferenceable or a past-the-end iterator.

Two iterators that compare equal, keep comparing equal after being both increased.

++a

a++

*a++

It can be decremented (if a dereferenceable iterator value precedes it).

--a

a--

*a--

It supports the arithmetic operators + and - between an iterator and an integer value, or subtracting an iterator from another.

a + n

n + a

a - n

a - b

It can be compared with inequality relational operators (<, >, <= and >=).

a < b

a > b

a <= b

a >= b

It supports compound assignment operations += and -=

a += n

a -= n

It supports the offset dereference operator ([]) a[n]
Lvalues are swappable. swap(a,b)

Declaration

Following is the declaration for std::random_access_iterator_tag.

C++11

struct random_access_iterator_tag {};
iterator.htm
Advertisements