24 Ranges library [ranges]

24.4 Range requirements [range.req]

24.4.4 Views [range.view]

The view concept specifies the requirements of a range type that has constant time move construction, move assignment, and destruction; that is, the cost of these operations is independent of the number of elements in the view.
template<class T> concept view = range<T> && movable<T> && default_­initializable<T> && enable_view<T>;
T models view only if:
  • T has move construction; and
  • T has move assignment; and
  • T has destruction; and
  • copy_­constructible<T> is false, or T has copy construction; and
  • copyable<T> is false, or T has copy assignment.
[Example
:
Examples of views are:
  • A range type that wraps a pair of iterators.
  • A range type that holds its elements by shared_­ptr and shares ownership with all its copies.
  • A range type that generates its elements on demand.
Most containers are not views since destruction of the container destroys 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> inline constexpr bool enable_view = derived_from<T, view_base>;
Remarks: Pursuant to [namespace.std], users may specialize enable_­view to true for cv-unqualified program-defined types which model view, and false for types which do not.
Such specializations shall be usable in constant expressions ([expr.const]) and have type const bool.