diff --git a/types.hpp b/types.hpp index e9a42b29..5355eff7 100644 --- a/types.hpp +++ b/types.hpp @@ -17,17 +17,23 @@ * Copyright 2011 Danny Robson */ -#ifndef __TYPES_HPP -#define __TYPES_HPP +#ifndef __UTIL_TYPES_HPP +#define __UTIL_TYPES_HPP + +#include "platform.hpp" #include #include #include /// Returns the number of elements of a statically allocated array +#if !defined(COMPILER_CLANG) template size_t elems(T (&)[N]) { return N; } +#else +#define elems(x) (sizeof(x) / 0[x]) +#endif template @@ -37,4 +43,4 @@ make_unique(Args&&... args) { } -#endif // __TYPES_HPP +#endif diff --git a/types/casts.hpp b/types/casts.hpp index fe408bd3..33f5ff24 100644 --- a/types/casts.hpp +++ b/types/casts.hpp @@ -41,13 +41,19 @@ namespace detail { template T - _sign_cast (const typename std::enable_if::value && std::is_unsigned::value, V>::type v) { CHECK_HARD (v < std::numeric_limits::max () / 2); return static_cast (v); } + + + template + T + _sign_cast (const typename std::enable_if::value, V>::type v) + { return v; } } /// Safely cast a numeric type to its (un)signed counterpart, aborting if the