LWG3549 proposes that view_interface<D>
does not need to inherit view_base
, which allows range adaptors to better perform empty base optimization.
In the latest [range.view], the definition of view
concept has undergone the following changes:
template<class T>
concept view =
range<T> && movable<T> && enable_view<T>;
template<class T>
inline constexpr bool is-derived-from-view-interface = see below; // exposition only
template<class T>
inline constexpr bool enable_view =
derived_from<T, view_base> || is-derived-from-view-interface<T>;
Where is-derived-from-view-interface
is defined as:
For a type
T
,is-derived-from-view-interface<T>
istrue
if and only ifT
has exactly one public base classview_interface<U>
for some typeU
andT
has no base classes of typeview_interface<V>
for any other typeV
.
The definition of this inline variable seems to have the following form:
#include <ranges>
template<class D>
concept is_derived_from_view_interface =
std::derived_from<D, std::ranges::view_interface<D>>;
static_assert(is_derived_from_view_interface<std::ranges::iota_view<int>>);
But D
does not have to inherit view_interface<D>
, it can inherit view_interface<U>
for some an arbitrary type U
, and we also need to detect whether D
inherits another view_interface<V>
where V
is not equal to U
.
So, How to properly define this is-derived-from-view-interface
?