34 lines · c
1#ifndef BENCHMARK_ARRAYSIZE_H_2#define BENCHMARK_ARRAYSIZE_H_3 4#include "internal_macros.h"5 6namespace benchmark {7namespace internal {8// The arraysize(arr) macro returns the # of elements in an array arr.9// The expression is a compile-time constant, and therefore can be10// used in defining new arrays, for example. If you use arraysize on11// a pointer by mistake, you will get a compile-time error.12//13 14// This template function declaration is used in defining arraysize.15// Note that the function doesn't need an implementation, as we only16// use its type.17template <typename T, size_t N>18char (&ArraySizeHelper(T (&array)[N]))[N];19 20// That gcc wants both of these prototypes seems mysterious. VC, for21// its part, can't decide which to use (another mystery). Matching of22// template overloads: the final frontier.23#ifndef COMPILER_MSVC24template <typename T, size_t N>25char (&ArraySizeHelper(const T (&array)[N]))[N];26#endif27 28#define arraysize(array) (sizeof(::benchmark::internal::ArraySizeHelper(array)))29 30} // end namespace internal31} // end namespace benchmark32 33#endif // BENCHMARK_ARRAYSIZE_H_34