Skip to content

Instantly share code, notes, and snippets.

@ahafidi
Created November 29, 2017 20:28
Show Gist options
  • Save ahafidi/0de5f3444301297a3fa40e16d0d4c6bb to your computer and use it in GitHub Desktop.
Save ahafidi/0de5f3444301297a3fa40e16d0d4c6bb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstddef>
template<typename T>
struct IsArray
{
static constexpr bool value = false;
};
template<typename T>
struct IsArray<T[]>
{
static constexpr bool value = true;
};
template<typename T, std::size_t N>
struct IsArray<T[N]>
{
static constexpr bool value = true;
};
class Test;
int main()
{
std::cout << std::boolalpha
<< IsArray<int>::value << std::endl
<< IsArray<float>::value << std::endl
<< IsArray<Test>::value << std::endl
<< IsArray<int[]>::value << std::endl
<< IsArray<float[]>::value << std::endl
<< IsArray<Test[]>::value << std::endl
<< IsArray<int[21]>::value << std::endl
<< IsArray<float[42]>::value << std::endl
<< IsArray<Test[84]>::value << std::endl
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment