fork download
  1. #include <array>
  2. #include <type_traits>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. template<typename C>
  7. struct container_traits {
  8. constexpr static bool is_array = false;
  9. };
  10.  
  11. template<template <typename, std::size_t> class C, typename T, std::size_t N>
  12. struct container_traits<C<T,N>> {
  13. constexpr static bool is_array = std::is_base_of<std::array<T,N>,C<T,N>>::value;
  14. };
  15.  
  16. template<typename T, size_t S>
  17. struct A : public std::array<T,S> {};
  18.  
  19. int main() {
  20. std::cout << container_traits<A<int, 5>>::is_array << std::endl; // must return 1
  21. std::cout << container_traits<std::array<int, 10>>::is_array << std::endl; // must return 1
  22. std::cout << container_traits<std::vector<int>>::is_array << std::endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
1
1
0