Namespaces
Variants
Views
Actions

std::ranges::view, std::ranges::enable_view, std::ranges::view_base

From cppreference.com
< cpp‎ | ranges
 
 
 
Defined in header <ranges>
template<class T>
concept view = ranges::range<T> && std::semiregular<T> && ranges::enable_view<T>;
(1)
template<class T>
inline constexpr bool enable_view = /*see description*/ ;
(2)
struct view_base { };
(3)
1) The view concept specifies the requirements of a range type that has constant time copy, move, and assignment operations (e.g. a pair of iterators, or a generator Range that creates its elements on-demand. Notably, the standard library containers are ranges, but not views)
2) The enable_view variable template is used to indicate that whether a range is a view, as follows:

For a type T, the default value of enable_view<T> is:

  • If std::derived_from<T, view_base> is true, enable_view<T> is true.
  • Otherwise, if T is a specialization of class template std::initializer_list, std::set, std::multiset, std::unordered_set, std::unordered_multiset, std::match_results, enable_view<T> is false
  • Otherwise, if both T and const T model range and ranges::range_reference_t<T> is not the same type as ranges::range_reference_t<const T>, enable_view<T> is false. (in other words, deep constness implies element ownership, shallow constness implies reference (view) semantics)
  • Otherwise, enable_view<T> is true.
3) Deriving from view_base enables range types to model view.

[edit] Notes

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 and have type const bool.