15b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#ifndef BENCHMARK_ARRAYSIZE_H_
25b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#define BENCHMARK_ARRAYSIZE_H_
35b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
45b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#include "internal_macros.h"
55b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
65b41e128b359900264464c480dfd4f107625f3c9Eric Fiseliernamespace benchmark {
75b41e128b359900264464c480dfd4f107625f3c9Eric Fiseliernamespace internal {
85b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// The arraysize(arr) macro returns the # of elements in an array arr.
95b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// The expression is a compile-time constant, and therefore can be
105b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// used in defining new arrays, for example.  If you use arraysize on
115b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// a pointer by mistake, you will get a compile-time error.
125b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier//
135b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
145b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// This template function declaration is used in defining arraysize.
155b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// Note that the function doesn't need an implementation, as we only
165b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// use its type.
175b41e128b359900264464c480dfd4f107625f3c9Eric Fiseliertemplate <typename T, size_t N>
185b41e128b359900264464c480dfd4f107625f3c9Eric Fiselierchar (&ArraySizeHelper(T (&array)[N]))[N];
195b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
205b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// That gcc wants both of these prototypes seems mysterious. VC, for
215b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// its part, can't decide which to use (another mystery). Matching of
225b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier// template overloads: the final frontier.
235b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#ifndef COMPILER_MSVC
245b41e128b359900264464c480dfd4f107625f3c9Eric Fiseliertemplate <typename T, size_t N>
255b41e128b359900264464c480dfd4f107625f3c9Eric Fiselierchar (&ArraySizeHelper(const T (&array)[N]))[N];
265b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#endif
275b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
285b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier#define arraysize(array) (sizeof(::benchmark::internal::ArraySizeHelper(array)))
295b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
30332f677b8bec401641a2743ab5d741c13cc6811dDominic Hamon}  // end namespace internal
31332f677b8bec401641a2743ab5d741c13cc6811dDominic Hamon}  // end namespace benchmark
325b41e128b359900264464c480dfd4f107625f3c9Eric Fiselier
33332f677b8bec401641a2743ab5d741c13cc6811dDominic Hamon#endif  // BENCHMARK_ARRAYSIZE_H_
34