1

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

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?

康桓瑋
  • 33,481
  • 5
  • 40
  • 90

1 Answers1

4

That wording means "use template argument deduction".

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

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

T.C.
  • 133,968
  • 17
  • 288
  • 421