class
<iterator>

std::bidirectional_iterator_tag

struct bidirectional_iterator_tag {}
Bidirectional iterator category
Empty class to identify the category of an iterator as a bidirectional iterator:

Bidirectional iterators


Bidirectional iterators are iterators that can be used to access the sequence of elements in a range in both directions (towards the end and towards the beginning).

All random-access iterators are also valid bidirectional iterators.

There is not a single type of bidirectional iterator: Each container may define its own specific iterator type able to iterate through it and access its elements.

Bidirectional iterators have the same properties as forward iterators, with the only difference that they can also be decremented:

propertyvalid expressions
Is default-constructible, copy-constructible, copy-assignable and destructibleX a;
X b(a);
b = a;
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
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
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++
Can be decremented (if a dereferenceable iterator value precedes it).
--a
a--
*a--
propertyvalid expressions
Is default-constructible, copy-constructible, copy-assignable and destructibleX a;
X b(a);
b = a;
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
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
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++
Can be decremented (if a dereferenceable iterator value precedes it).
--a
a--
*a--
Lvalues are swappable.swap(a,b)

Where X is a bidirectional iterator type, a and b are objects of this iterator type, and t is an object of the type pointed by the iterator type (or some other type that can be assigned to the lvalue returned by dereferencing an object of type X).

Constant iterators are iterators that do not fulfill the requirements of an output iterator; Dereferencing them yields a reference to a constant element (such as const T&).

All bidirectionl iterators are also valid forward and input iterators.

See also