Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve the ArraySize function a bit now that c++11 isn't forbidden t…
…here. Error messages should be friendlier now.
  • Loading branch information
jordan-woyak committed Sep 12, 2013
1 parent 0fc1ca0 commit ef1d336
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Source/Core/Common/Src/CommonFuncs.h
Expand Up @@ -13,16 +13,15 @@
#endif

#include <cstddef>

// TODO: make into function when type_traits and constexpr are available
template <typename T, std::size_t N = 0>
struct ArraySizeImpl {};

template <typename T, std::size_t N>
struct ArraySizeImpl<T[N], 0> { static const std::size_t size = N; };
#include <type_traits>

// Will fail to compile on a non-array:
#define ArraySize(x) ArraySizeImpl<decltype(x)>::size
// TODO: make this a function when constexpr is available
template <typename T>
struct ArraySizeImpl : public std::extent<T>
{ static_assert(std::is_array<T>::value, "is array"); };

#define ArraySize(x) ArraySizeImpl<decltype(x)>::value

#define b2(x) ( (x) | ( (x) >> 1) )
#define b4(x) ( b2(x) | ( b2(x) >> 2) )
Expand Down

0 comments on commit ef1d336

Please sign in to comment.