相关疑难解决方法(0)

如何测试B类是否来自模板族类

如何在编译时测试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)

c++ templates sfinae type-traits c++03

6
推荐指数
1
解决办法
1394
查看次数

标签 统计

c++ ×1

c++03 ×1

sfinae ×1

templates ×1

type-traits ×1