Merge pull request #2952 from lioncash/constexpr

CommonFuncs: Replace ArraySize define with constexpr equivalent
This commit is contained in:
shuffle2 2015-09-03 22:56:25 -07:00
commit a09b9bef8d
3 changed files with 7 additions and 9 deletions

View File

@ -17,16 +17,14 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <type_traits>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
// Will fail to compile on a non-array: // Will fail to compile on a non-array:
// TODO: make this a function when constexpr is available template <typename T, size_t N>
template <typename T> constexpr size_t ArraySize(T (&arr)[N])
struct ArraySizeImpl : public std::extent<T> {
{ static_assert(std::is_array<T>::value, "is array"); }; return N;
}
#define ArraySize(x) ArraySizeImpl<decltype(x)>::value
#define b2(x) ( (x) | ( (x) >> 1) ) #define b2(x) ( (x) | ( (x) >> 1) )
#define b4(x) ( b2(x) | ( b2(x) >> 2) ) #define b4(x) ( b2(x) | ( b2(x) >> 2) )

View File

@ -132,7 +132,7 @@ CEXIMemoryCard::CEXIMemoryCard(const int index, bool gciFolder)
memory_card_size = memorycard->GetCardId() * SIZE_TO_Mb; memory_card_size = memorycard->GetCardId() * SIZE_TO_Mb;
u8 header[20] = {0}; u8 header[20] = {0};
memorycard->Read(0, ArraySize(header), header); memorycard->Read(0, static_cast<s32>(ArraySize(header)), header);
SetCardFlashID(header, card_index); SetCardFlashID(header, card_index);
} }

View File

@ -6,7 +6,7 @@
#include "Common/CommonFuncs.h" #include "Common/CommonFuncs.h"
TEST(CommonFuncs, ArraySizeMacro) TEST(CommonFuncs, ArraySizeFunction)
{ {
char test[4]; char test[4];
u32 test2[42]; u32 test2[42];