next up previous
Next: Views Design Up: The View Template Library Previous: Introduction


Views, Smart Iterators, and all the rest

A view is an adaptor for STL type containers that provides access to transformed or a subset of elements of the underlying container it is applied to. Transformation and filtering is done on the fly, without affecting the data actually stored in the container.

The interface provided by the views is the well known STL container interface, such that views can usually be used transparently as a drop-in replacement for the corresponding STL containers, if data is only to be read. Additionally, views can be applied to views, permitting a mix and match approach to construct increasingly complex views by layering suitable VTL components on top of each other (see section 4). Nearly all of the container requirements are met, except for occasional technical details and complexity guarantees.

Figure 1: Relation of views to containers, iterators, algorithms, and smart iterators.
0.5
\includegraphics[width=0.5\textwidth]{views-setting.eps}

From a read-only user's view, the relation between views and smart iterators is the same as between containers and iterators: views and containers are just factories for smart iterators and iterators, respectively, providing some additional meta information such as the number of elements.

There are essentially three ways to get a different sight onto the data stored in a container. First, one can use a view. Second, one can rely directly on smart iterators. And third, one can use a second container storing the result of an STL algorithm generating the required data.

Compared to using smart iterators, views

On the other hand, smart iterators are sufficient in many situations, e.g. for feeding them into a STL algorithm. In many of those cases, the use of views does not provide any benefit. Note that, since all the hard work is done by the smart iterators produced by the views, there is no performance difference between using smart iterators and views.

Compared to transforming the data into a second container, views

On the other hand, the generate-on-demand technique of the views is likely to be less efficient if the data elements are accessed very often, and the complete control over the second container enables the use of suitable access patterns.


next up previous
Next: Views Design Up: The View Template Library Previous: Introduction
Martin Weiser 2000-09-29