Why does std::is_array return false for std::array?

ISO/IEC 14882:2011, § 20.9.4.1, Table 47 says this:

  • Template: template struct is_array;

  • Condition: T is an array type (3.9.2) of known or unknown extent

  • Comment: Class template array (23.3.2) is not an array type.

so, the assertion should fail.

Although you could specialize the is_array as proposed by @0x499602D2, if you did that you should do so in another namespace, as you should not attempt to change the meaning of standardized functions.


std::is_array is defined to be true only for types that look like T[] or T[N]. std::array is not included.

You cannot modify or specialize std::is_array to be true_type for std::array under the standard; that would make your program ill-formed, no diagnostic required. When specializing types within std, the result must be consistent with the standard, and the standard is specific here. (Also, doing so for other templates within std is highly questionable to illegal).

You can create your own is_array trait:

namespace notstd {
  template<class T>
  struct is_array:std::is_array<T>{};
  template<class T, std::size_t N>
  struct is_array<std::array<T,N>>:std::true_type{};
  // optional:
  template<class T>
  struct is_array<T const>:is_array<T>{};
  template<class T>
  struct is_array<T volatile>:is_array<T>{};
  template<class T>
  struct is_array<T volatile const>:is_array<T>{};
}

then use notstd::is_array<T> elsewhere to detect either C-style arrays or C++ std::array.