Section 7.3.  Iterator Adaptors
Team LiB
Previous Section Next Section

7.3. Iterator Adaptors

The iterators of a sequence view are examples of iterator adaptors, an important concept (lowercase c) in its own right. Just as a view is a sequence built upon one or more underlying sequences, an iterator adaptor is an iterator that adapts the behavior of one or more underlying iterators.

Iterator adaptors are so useful in runtime C++ that there is an entire Boost library devoted to them. Even the STL contains several iterator adaptors, most notably std::reverse_iterator that traverses the same sequence of elements as its underlying iterator, but in the opposite order. The iterators of mpl::filter_view are another example of an iterator traversal adaptor. An iterator access adaptor accesses different element values from its underlying iterator, like the iterators of mpl::transform_view do.

Because you can access a std::reverse_iterator's underlying iterator by calling its base() member function, MPL adaptors provide access to their underlying iterators via a nested ::base type. In all other respects, an iterator adaptor is just like any other iterator. It can have any of the three iterator categoriespossibly different from its underlying iterator(s)and all of the usual iterator requirements apply.

    Team LiB
    Previous Section Next Section