Chapter 7. Views and Iterator AdaptorsAlgorithms 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:
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. ![]() |