Chapter 7.  Views and Iterator Adaptors
Team LiB
Previous Section Next Section

Chapter 7. Views and Iterator Adaptors

Algorithms like transform provide one way to operate on sequences. This chapter covers the use of sequence views, a powerful sequence processing idiom that is often superior to the use of algorithms.

First, an informal definition:

Sequence View

A sequence viewor view for shortis a lazy adaptor that delivers an altered presentation of one or more underlying sequences.


Views are lazy: Their elements are only computed on demand. We saw examples of lazy evaluation when we covered nullary metafunctions in Chapter 3 and eval_if in Chapter 4. As with other lazy constructs, views can help us avoid premature errors and inefficiencies from computations whose results will never be used. Also sequence views sometimes fit a particular problem better than other approaches, yielding simpler, more expressive, and more maintainable code.

In this chapter you will find out how views work and we will discuss how and when to use them. Then we'll explore the view classes that come with the MPL and you will learn how to write your own.

    Team LiB
    Previous Section Next Section