Here you go:
template <class T, class U>
struct are_same_template : std::is_same<T, U>
{};
template <template<class...> class T, class T1, class T2>
struct are_same_template<T<T1>, T<T2>> : std::true_type
{};
template <class T, class U>
constexpr bool CheckTypes(T, U)
{
return are_same_template<T, U>::value;
}
Demo: http://coliru.stacked-crooked.com/a/8533c694968f4dbb
This works by providing a specialization of are_same_template
that discard the template argument types:
template <template<class...> class T, class T1, class T2>
struct are_same_template<T<T1>, T<T2>>
Even if T1
and T2
differ (the template argument types), are_same_template
is a true type:
are_same_template<T<T1>, T<T2>> : std::true_type
About template<class...>
instead of template<class>
: this is to accomodate the fact than std::
containers have implicit template arguments. Thanks to ConstantinosGlynos for making me aware of it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…