From 7afaacda19a584c5ded13e9cd84af48914036b05 Mon Sep 17 00:00:00 2001 From: leper Date: Sun, 5 Apr 2015 16:50:26 +0000 Subject: [PATCH] Improve ARRAY_SIZE. This was SVN commit r16499. --- source/lib/code_annotation.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 7b1cbdb8e6..bf4fd545e4 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -314,15 +314,15 @@ switch(x % 2) // number of array elements // -// (function taking a reference to an array and returning a pointer to -// an array of characters. it's only declared and never defined; we just -// need it to determine n, the size of the array that was passed.) -template char (*ArraySizeDeducer(T (&)[n]))[n]; - // (although requiring C++, this method is much better than the standard // sizeof(name) / sizeof(name[0]) because it doesn't compile when a // pointer is passed, which can easily happen under maintenance.) -#define ARRAY_SIZE(name) (sizeof(*ArraySizeDeducer(name))) +template +constexpr size_t ArraySize(T (&)[n]) noexcept +{ + return n; +} +#define ARRAY_SIZE(name) ArraySize(name) // C99-style __func__