Ranges Views: Lazy, Non-Mutating Iterations with Materialization
Learn how range views provide lazy, non-mutating iterations with materialization.
Views are non-owning ranges with complexity guarantees
Any type that provides the functions begin()
and end()
, where begin()
returns an iterator and end()
returns a sentinel, qualifies as a range. We concluded that all standard containers are ranges. Containers own their elements, so we can, therefore, call them owning ranges.
A view is also a range, that is, it provides begin()
and end()
functions. However, unlike containers, a view does not own the elements in the range that the view spans over.
The construction of a view is required to be a constant-time operation, . It cannot perform any work that depends on the size of the underlying container. The same goes for assigning, copying, moving, and destructing a view. This makes it easy to reason about performance when using views to combine multiple algorithms. ...