Skip to content

Instantly share code, notes, and snippets.

@paxbun
Last active April 1, 2020 09:27
Show Gist options
  • Save paxbun/90ec02236a73c5a00d08e17ab1dd1e8d to your computer and use it in GitHub Desktop.
Save paxbun/90ec02236a73c5a00d08e17ab1dd1e8d to your computer and use it in GitHub Desktop.
Struct templates for array traits
#include <cstddef>
template <typename T>
struct ArrayDimension;
template <typename T, size_t N>
struct ArrayDimension<T[N]>
{
static constexpr size_t Value = ArrayDimension<T>::Value + 1;
};
template <typename T>
struct ArrayDimension
{
static constexpr size_t Value = 0;
};
template <typename T>
struct IsArray
{
static constexpr bool Value = ArrayDimension<T>::Value != 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment