# C++ named requirements: LegacyBidirectionalIterator

From cppreference.com
< cpp‎ | named req

A LegacyBidirectionalIterator is a LegacyForwardIterator that can be moved in both directions (i.e. incremented and decremented).

### Requirements

The type `It` satisfies LegacyBidirectionalIterator if

- The type `It` satisfies LegacyForwardIterator

And, given

- `a` and `b`, iterators of type `It`
- `reference,` the type denoted by `std::iterator_traits<It>::reference`

The following expressions must be valid and have their specified effects

Expression | Return | Equivalent expression | Notes
--- | --- | --- | ---

--a

It&

Preconditions:

- `a` is decrementable (there exists such `b` that a == ++b)

Postconditions:

- a is dereferenceable
- --(++a) == a
- If --a == --b then a == b
- a and --a designate the same iterator object

a-- | convertible to const It& | It temp = a; --a; return temp; |
*a-- | `reference` |  |

A mutable LegacyBidirectionalIterator is a LegacyBidirectionalIterator that additionally satisfies the LegacyOutputIterator requirements.

### Notes

The begin iterator is not decrementable and the behavior is undefined if --container.begin() is evaluated.

A bidirectional iterator does not have to be dereferenceable to be decrementable (in particular, the end iterator is not dereferenceable but is decrementable)

### Concept

For the definition of std::iterator_traits, the following exposition-only concept is defined.

template<class I> concept __LegacyBidirectionalIterator = __LegacyForwardIterator<I> && requires(I i) { { --i } -> std::Same<I&>; { i-- } -> const I&; { *i-- } -> std::Same<std::iter_reference_t<I>>; }; |  |

where the exposition-only concept `__LegacyForwardIterator` is described in LegacyForwardIterator#Concept.

(since C++20)

### See also

BidirectionalIterator | specifies that a `ForwardIterator` is a bidirectional iterator, supporting movement backwards (concept)

- Iterator library

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/BidirectionalIterator&oldid=109809"