5

I'm trying to implement an extension for std::is_base_of for templated classes, such that if I have the following:

template <typename X, typename Y, int Z> class A {};

template <typename X> class B : public A<X, char, 2> {};

I can use something like

std::is_base_of_ext<A, B<int>>

to statically check that An is a base class from B, independently of specific template parameters and the way B specializes from A.

"std::is_base_of for template classes" provides a very nice solution to this, but it only works with type template parameters; can it also be made to work with non-type parameters?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
  • C++11 can't do variadic mixes of types and values. You need C++17's `auto...` template parameter packs – Caleth Jul 08 '19 at 10:51
  • @Caleth but you still can't have a pack containing both types and values and I think that would be needed for generic implementation of OP's is_base_of, unless they limit themselves to a specific order – Fureeish Jul 08 '19 at 10:52
  • 2
    No. This is not possible in C++. A template parameter pack cannot contain both type and non-type parameters. – L. F. Jul 08 '19 at 11:26
  • This looks like a [XY problem](http://xyproblem.info/) and you should first explain why do you need `is_base_of_ext`? Maybe there is some workaround if we know more (like limiting what `A` can be/have to provide). – Marek R Jul 08 '19 at 11:53
  • 1
    One of possible solutions is split `A`: `template class A : ABase {};` – Marek R Jul 08 '19 at 11:59
  • 1
    You can have `has_A__as_base>`, but you cannot have your generic function for any kind of template class. – Jarod42 Jul 08 '19 at 14:07

0 Answers0