Jak sprawdzić, czy klasa B pochodzi z rodziny szablonów klas
Jak przetestować w czasie kompilacji, czy klasa B pochodzi ze std :: vector?
template<class A>
struct is_derived_from_vector {
static const bool value = ????;
};
Jak przetestować w czasie kompilacji, czy klasa B pochodzi z rodziny szablonów?
template<class A, template< class > class Family>
struct is_derived_from_template {
static const bool value = ????;
};
Za pomocą:
template<class T> struct X {};
struct A : X<int> {}
struct B : std::vector<char> {}
struct D : X<D> {}
int main() {
std::cout << is_derived_from_template<A, X>::value << std::endl; // true
std::cout << is_derived_from_template<D, X>::value << std::endl; // true
std::cout << is_derived_from_vector<A>::value << std::endl; // false
std::cout << is_derived_from_vector<B>::value << std::endl; // true
}