diff --git a/libcxx/include/__ranges/view_interface.h b/libcxx/include/__ranges/view_interface.h --- a/libcxx/include/__ranges/view_interface.h +++ b/libcxx/include/__ranges/view_interface.h @@ -38,16 +38,29 @@ template void __implicitly_convert_to(type_identity_t<_Tp>) noexcept; +template + requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>> +class view_interface; + +template +concept __valid_view = requires { + sizeof(_Tp); + derived_from<_Tp, view_interface<_Tp>>; + view<_Tp>; +}; + template requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>> class view_interface : public view_base { _LIBCPP_HIDE_FROM_ABI constexpr _Derived& __derived() noexcept { + static_assert(__valid_view<_Derived>, "The derived type must model derived_from> and view"); return static_cast<_Derived&>(*this); } _LIBCPP_HIDE_FROM_ABI constexpr _Derived const& __derived() const noexcept { + static_assert(__valid_view<_Derived>, "The derived type must model derived_from> and view"); return static_cast<_Derived const&>(*this); }