24 Ranges library [ranges]

24.4 Range requirements [range.req]

24.4.4 Views [range.view]

template<class T> concept view = range<T> && semiregular<T> && enable_view<T>;
The view concept specifies the requirements of a range type that has constant time copy, move, and assignment operators; that is, the cost of these operations is not proportional to the number of elements in the view.
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 copying the container copies 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 = see below;
Remarks: For a type T, the default value of enable_­view<T> is:
  • If derived_­from<T, view_­base> is true, true.
  • Otherwise, if T is a specialization of class template initializer_­list ([support.initlist]), set ([set]), multiset ([multiset]), unordered_­set ([unord.set]), unordered_­multiset ([unord.multiset]), or match_­results ([re.results]), false.
  • Otherwise, if both T and const T model range and range_­reference_­t<T> is not the same type as range_­reference_­t<const T>, false.
    Note
    : Deep const-ness implies element ownership, whereas shallow const-ness implies reference semantics. — end note
     ]
  • Otherwise, true.
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.