How to test at compile time whether class B is derived from std::vector?
template<class A>
struct is_derived_from_vector {
static const bool value = ????;
};
How to test at compile time whether class B is derived from template family?
template<class A, template< class > class Family>
struct is_derived_from_template {
static const bool value = ????;
};
Using:
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
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…