Reversible Container, reverse_bidirectional_iterator, Random Access Iterator, iterator tags, Iterator Overview

reverse_bidirectional_iterator<BidirectionalIterator, T, Reference, Distance>

Categories: iterators, adaptors

Component type: type

Description

Reverse_bidirectional_iterator is an iterator adaptor that enables backwards traversal of a range. Operator++ applied to an object of class reverse_bidirectional_iterator<BidirectionalIterator> means the same thing as operator-- applied to an object of class BidirectionalIterator. There are two different reverse iterator adaptors: the class reverse_bidirectional_iterator has a template argument that is a Bidirectional Iterator, and the class reverse_iterator has a template argument that is a Random Access Iterator. [1]

Example

template <class T>

void forw(const list <T>& L) {

 list<T>::iterator first = L.begin();

 list<T>::iterator last = L.end();

 while (first != last) cout << *first++ << endl;

}

template <class T>

void rev(const list <T>& L) {

 typedef reverse_bidirectional_iterator<list<T>::iterator, T, list<T>::reference_type, list&l t;T>::difference_type> reverse_iterator; [2]

 reverse_iterator rfirst(L.end());

 reverse_iterator rlast(L.begin());

 while (rfirst != rlast) cout << *rfirst++ << endl;

}

In the function forw, the elements are printed in the order *first, *(first+1) , …, *(last-1). In the function rev, they are printed in the order *(last – 1), *(last - 2), …, *first. [3]

Definition

Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h. This class is no longer part of the C++ standard, but it was present in early drafts, and it is retained in this implementation for backward compatibility.

Template parameters
Parameter Description Default
BidirectionalIterator The base iterator class. Incrementing an object of class reverse_bidirectional_iterator<BidirectionalIterator> corresponds to decrementing an object of class BidirectionalIterator.
T The reverse iterator's value type. This should always be the same as the base iterator's value type.
Reference The reverse iterator's reference type. This should always be the same as the base iterator's reference type. T&
Distance The reverse iterator's distance type. This should always be the same as the base iterator's distance type. ptrdiff_t
Model of

Bidirectional Iterator.

Type requirements

The base iterator type (that is, the template parameter BidirectionalIterator) must be a Bidirectional Iterator. The reverse_bidirectional_iterator's value type, reference type, and distance type (that is, the template parameters T, Reference, and Distance, respectively) must be the same as the base iterator's value type, reference type, and distance type.

Public base classes

None.

Members
Member Where defined Description
self reverse_bidirectional_iterator See below
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату