如何正确定义 is-derived-from-view-interface?

How to properly define is-derived-from-view-interface?

LWG3549 proposes that view_interface<D> does not need to inherit view_base,让范围适配器更好的进行空基优化

在最近的[range.view]中,view概念的定义发生了以下变化:

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>;

其中is-derived-from-view-interface定义为:

For a type T, is-derived-from-view-interface<T> is true if and only if T has exactly one public base class view_­interface<U> for some type U and T has no base classes of type view_­interface<V> for any other type V.

这个内联变量的定义似乎有以下形式:

#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>>);

但是D不一定要继承view_interface<D>,它可以继承view_interface<U>为某个任意类型U,我们还需要检测是否D 继承另一个 view_interface<V> 其中 V 不等于 U.

那么,如何正确定义这个is-derived-from-view-interface?

该措辞的意思是“使用模板参数推导”。

template <class D>
void test(view_interface<D>&);

template <class R>
concept is_derived_from_view_interface = requires (R& r){ (test)(r); };