如何在编译时测试B类是否来自std :: vector?
template<class A>
struct is_derived_from_vector {
static const bool value = ????;
};
Run Code Online (Sandbox Code Playgroud)
如何在编译时测试B类是否来自模板系列?
template<class A, template< class > class Family>
struct is_derived_from_template {
static const bool value = ????;
};
Run Code Online (Sandbox Code Playgroud)
使用:
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 …Run Code Online (Sandbox Code Playgroud)