Share via


reverse_bidirectional_iterator

reverse_bidirectional_iterator

template<class BidIt,
    class T = iterator_traits<BidIt>::value_type,
    class Ref = T&,
    class Ptr = T *, class Dist = ptrdiff_t>
    class reverse_bidirectional_iterator
        : public iterator<bidirectional_iterator_tag, T, Dist> {
public:
    typedef BidIt iter_type;
    typedef Ref reference_type;
    typedef Ptr pointer_type;
    reverse_bidirectional_iterator();
    explicit reverse_bidirectional_iterator(BidIt x);
    BidIt base() const;
    Ref operator*() const;
    Ptr operator->() const;
    reverse_bidirectional_iterator& operator++();
    reverse_bidirectional_iterator operator++(int);
    reverse_bidirectional_iterator& operator--();
    reverse_bidirectional_iterator operator--();
protected:
    BidIt current;
    };

The template class describes an object that behaves like a bidirectional iterator of class iterator<bidirectional_iterator_tag, ``T``, ``Dist``>. It stores a bidirectional iterator of type BidIt in the protected object current. Incrementing the object x of type reverse_bidirectional_iterator decrements x.current, and decrementing x increments x.current. Moreover, the expression *x evaluates to *--(tmp = current) (where tmp is a temporary object of class BidIt), of type Ref. Typically, Ref is type T&.

Thus, you can use an object of class reverse_bidirectional_iterator to access in reverse order a sequence that is traversed in order by a bidirectional iterator.