1 #ifndef BENCHMARK_ARRAYSIZE_H_
2 #define BENCHMARK_ARRAYSIZE_H_
3 
4 #include "internal_macros.h"
5 
6 namespace benchmark {
7 namespace 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 be
10 // used in defining new arrays, for example.  If you use arraysize on
11 // a pointer by mistake, you will get a compile-time error.
12 //
13 
14 
15 // This template function declaration is used in defining arraysize.
16 // Note that the function doesn't need an implementation, as we only
17 // use its type.
18 template <typename T, size_t N>
19 char (&ArraySizeHelper(T (&array)[N]))[N];
20 
21 // That gcc wants both of these prototypes seems mysterious. VC, for
22 // its part, can't decide which to use (another mystery). Matching of
23 // template overloads: the final frontier.
24 #ifndef COMPILER_MSVC
25 template <typename T, size_t N>
26 char (&ArraySizeHelper(const T (&array)[N]))[N];
27 #endif
28 
29 #define arraysize(array) (sizeof(::benchmark::internal::ArraySizeHelper(array)))
30 
31 } // end namespace internal
32 } // end namespace benchmark
33 
34 #endif // BENCHMARK_ARRAYSIZE_H_
35