From ef1d33647f57553b7d0a2f0aed11c0b60a54ab4c Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 12 Sep 2013 12:57:13 -0500 Subject: [PATCH] Improve the ArraySize function a bit now that c++11 isn't forbidden there. Error messages should be friendlier now. --- Source/Core/Common/Src/CommonFuncs.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index 284302d70d..7f62684efb 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -13,16 +13,15 @@ #endif #include - -// TODO: make into function when type_traits and constexpr are available -template -struct ArraySizeImpl {}; - -template -struct ArraySizeImpl { static const std::size_t size = N; }; +#include // Will fail to compile on a non-array: -#define ArraySize(x) ArraySizeImpl::size +// TODO: make this a function when constexpr is available +template +struct ArraySizeImpl : public std::extent +{ static_assert(std::is_array::value, "is array"); }; + +#define ArraySize(x) ArraySizeImpl::value #define b2(x) ( (x) | ( (x) >> 1) ) #define b4(x) ( b2(x) | ( b2(x) >> 2) )