diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h index 8e039b6066..1eb57842cd 100644 --- a/Source/Core/Common/CommonFuncs.h +++ b/Source/Core/Common/CommonFuncs.h @@ -17,16 +17,14 @@ #include #include -#include #include "Common/CommonTypes.h" // Will fail to compile on a non-array: -// 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 +template +constexpr size_t ArraySize(T (&arr)[N]) +{ + return N; +} #define b2(x) ( (x) | ( (x) >> 1) ) #define b4(x) ( b2(x) | ( b2(x) >> 2) ) diff --git a/Source/Core/Core/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/HW/EXI_DeviceMemoryCard.cpp index 7fd80f3f2e..722b69f153 100644 --- a/Source/Core/Core/HW/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/HW/EXI_DeviceMemoryCard.cpp @@ -132,7 +132,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index, bool gciFolder) memory_card_size = memorycard->GetCardId() * SIZE_TO_Mb; u8 header[20] = {0}; - memorycard->Read(0, ArraySize(header), header); + memorycard->Read(0, static_cast(ArraySize(header)), header); SetCardFlashID(header, card_index); } diff --git a/Source/UnitTests/Common/CommonFuncsTest.cpp b/Source/UnitTests/Common/CommonFuncsTest.cpp index 03a8383e96..14762cbc7b 100644 --- a/Source/UnitTests/Common/CommonFuncsTest.cpp +++ b/Source/UnitTests/Common/CommonFuncsTest.cpp @@ -6,7 +6,7 @@ #include "Common/CommonFuncs.h" -TEST(CommonFuncs, ArraySizeMacro) +TEST(CommonFuncs, ArraySizeFunction) { char test[4]; u32 test2[42];