Determine if two types are specializing in the same class template?

I would like to know how to write the type_traits class to determine if two types are specializations of the same template class. The big problem is that it should work for a mixed type / non-type template, for example:

 template <typename T, std::size_t N> class MyClass {}; 

Is it possible to create such a thing?

+8
c ++ 11 typetraits template-meta-programming template-specialization
source share
1 answer

I do not think that you can do this at all for an arbitrary class template with mixed types and non-peak parameters.

You can come closer to more specific sets of parameters, but I don't know how to handle the general case:

 #include <type_traits> template <typename T, std::size_t N> class MyClass {}; // assume not the same template<typename T, typename U> struct my_trait : std::false_type { }; // both specializations of MyClass template<typename T1, std::size_t N1, typename T2, std::size_t N2> struct my_trait<MyClass<T1, N1>, MyClass<T2, N2>> : std::true_type { }; // both specializations of some class template Templ<typename, std::size_t> template<template<typename, std::size_t> class Templ, typename A1, std::size_t S1, typename A2, std::size_t S2> struct my_trait<Templ<A1, S1>, Templ<A2, S2>> : std::true_type { }; // both specializations of some class template Templ<typename...> template<template<typename...> class Templ, typename... A1, typename... A2> struct my_trait<Templ<A1...>, Templ<A2...>> : std::true_type { }; 
+1
source share

All Articles