
ALT template <class, class> struct covariance_check; // implementation below template <class Derived, class Base> concept covariant_subtype_of = covariance_check<Derived, Base>::value; // Simple class hierarchy for example purposes struct MyBase { virtual void say_hello() const = 0; }; struct MyDerived : MyBase { void say_hello() const override { std::cout << "hello world\n"; } }; // Accepts `vector<MyDerived>` without mentioning `MyDerived`! void test(covariant_subtype_of<std::vector<MyBase>> auto const& data) { for (MyBase const& value : data) value.say_hello(); } // Implementation of covariance_check template <class Derived, class Base> struct covariance_check : std::is_base_of<Base, Derived> {}; template <template <class...> class T, class... Ds, class... Bs> struct covariance_check<T<Ds...>, T<Bs...>> : std::conjunction<covariance_check<Ds, Bs>...> {} // demo int main() { auto v = std::vector<MyDerived>{ {}, {}, {} }; test(v); }
























