我创建了一个container_traits
类来检查容器是否std::array
存在。但它无法捕获从std::array
. 有什么解决办法吗?
#include <vector>
#include <array>
#include <iostream>
using namespace std;
template<typename C>
struct container_traits { constexpr static bool is_array = false; };
template<typename T, size_t S>
struct container_traits<std::array<T,S>> { constexpr static bool is_array = true; };
template<typename T, size_t S>
struct A : public std::array<T,S> {};
int main()
{
cout << container_traits<A<int, 5>>::is_array << endl; // must return 1
cout << container_traits<std::array<int, 10>>::is_array << endl; // must return 1
cout << container_traits<std::vector<int>>::is_array << endl; // must return 0
return 0;
}