[range.view] (original) (raw)
25 Ranges library [ranges]
25.4 Range requirements [range.req]
25.4.4 Views [range.view]
The view concept specifies the requirements of a range type that has the semantic properties below, which make it suitable for use in constructing range adaptor pipelines ([range.adaptors]).
template<class T> concept [view](#concept:view "25.4.4 Views [range.view]") = [range](range.range#concept:range "25.4.2 Ranges [range.range]")<T> && [movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]")<T> && enable_view<T>;
T models view only if
- T has move construction; and
- move assignment of an object of type Tis no more complex than destruction followed by move construction; and
- if N copies and/or moves are made from an object of type Tthat contained M elements, then those N objects have destruction; and
- copy_constructible<T> is false, orT has copy construction; and
- copyable<T> is false, or copy assignment of an object of type Tis no more complex than destruction followed by copy construction.
[Note 1:
The constraints on copying and moving imply that a moved-from object of type T has destruction.
— _end note_]
[Example 1:
Examples of views are:
- A range type that wraps a pair of iterators.
- A range type that holds its elements by shared_ptrand shares ownership with all its copies.
- A range type that generates its elements on demand.
A container such as vector<string>does not meet the semantic requirements of viewsince copying the container copies all of the elements, which cannot be done in constant time.
— _end example_]
Since the difference between range and view is largely semantic, the two are differentiated with the help of enable_view.
template<class T> constexpr bool _is-derived-from-view-interface_ = _see below_; // _exposition only_ template<class T> constexpr bool enable_view = [derived_from](concept.derived#concept:derived%5Ffrom "18.4.3 Concept derived_from [concept.derived]")<T, view_base> || _is-derived-from-view-interface_<T>;
For a type T,is-derived-from-view-interface<T> is trueif and only ifT has exactly one public base class view_interface<U>for some type U andT has no base classes of type view_interface<V>for any other type V.
Remarks: Pursuant to [namespace.std], users may specialize enable_viewto truefor cv-unqualified program-defined types that model view, and false for types that do not.
Such specializations shall be usable in constant expressions ([expr.const]) and have type const bool.