4.6 KiB
[range.view]
25 Ranges library [ranges]
25.4 Range requirements [range.req]
25.4.5 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.5 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 O(1) move construction; and
move assignment of an object of type T is no more complex than destruction followed by move construction; and
if N copies and/or moves are made from an object of type T that contained M elements, then those N objects have O(N+M) destruction; and
copy_constructible is false, orT has O(1) copy construction; and
copyable is false, or copy assignment of an object of type T is 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 O(1) destruction.
â end note]
[Example 1:
Examples of views are:
A container such as vector does not meet the semantic requirements of view since 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_from "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 is true if and only ifT has exactly one public base class view_interface for some type U andT has no base classes of type view_interface for any other type V.
Remarks: Pursuant to [namespace.std], users may specialize enable_view to true for 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.