[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

[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 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.