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 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
]
template<class T> inline constexpr bool enable_view = see below; template<class T> concept View = Range<T> && Semiregular<T> && enable_view<T>;
Since the difference between Range and View is largely semantic, the two are differentiated with the help of enable_­view.
For a type T, the default value of enable_­view<T> is:
  • If DerivedFrom<T, view_­base> is true, true.
  • Otherwise, if T is a specialization of class template initializer_­list, set, multiset, unordered_­set, unordered_­multiset, or match_­results, false.
  • Otherwise, if both T and const T model Range and iter_­reference_­t<iterator_­t<T>> is not the same type as iter_­reference_­t<iterator_­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 types which model View, and false for types which do not.