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::movable<T> && ranges::enable_view<T>;
(1) (since C++20)
template<class T>

inline constexpr bool enable_view =

    std::derived_from<T, view_base> || /*is-derived-from-view-interface*/<T>;
(2) (since C++20)
struct view_base { };
(3) (since C++20)
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 whether a range is a view. /*is-derived-from-view-interface*/<T> is true if and only if T has exactly one public base class ranges::view_interface<U> for some type U, and T has no base classes of type ranges::view_interface<V> for any other type V.
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 must be usable in constant expressions and have type const bool.
3) Deriving from view_base enables range types to model view.

[edit] Notes

By default, a type modeling movable and range is considered a view if it is publicly and unambiguously derived from view_base, or exactly one specialization of ranges::view_interface.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
P2325R3 C++20 view required default_initializable does not require
LWG 3549 C++20 enable_view did not detect inheritance from view_interface detects