Section 7.2.  View Concept
Team LiB
Previous Section Next Section

7.2. View Concept

By now you probably have a pretty good feeling for what views are all about, but let's try to firm the idea up a bit. To begin with, this subsection should probably be titled "View concept" with a lowercase c, since normally when we speak of "Concepts" in C++, we're referring to formal interface requirements as described in Chapter 5. Views are a little more casual than that. From an interface perspective, a view is nothing more than a sequence, and is only a view because of two implementation details. First, as we've repeated until you're surely tired of reading it, views are lazy: their elements are computed only on demand. Not all lazy sequences are views, though. For example, range_c<...> is a familiar example of a lazy sequence, but somehow that doesn't seem much like a view onto anything. The second detail required for "view-ness" is that the elements must be generated from one or more input sequences.

An emergent property is one that only arises because of some more fundamental characteristics. All views share two emergent properties. Firstand this really applies to all lazy sequences since their elements are computedviews are not extensible. If you need extensibility, you need to use the copy algorithm to create an extensible sequence from the view. Second, since iterators arbitrate all element accesses, most of the logic involved in implementing a sequence view is contained in its iterators.

    Team LiB
    Previous Section Next Section