Allow sign_cast to same type
This commit is contained in:
parent
befb6f4b2b
commit
6ff8405c6a
12
types.hpp
12
types.hpp
@ -17,17 +17,23 @@
|
|||||||
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TYPES_HPP
|
#ifndef __UTIL_TYPES_HPP
|
||||||
#define __TYPES_HPP
|
#define __UTIL_TYPES_HPP
|
||||||
|
|
||||||
|
#include "platform.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
/// Returns the number of elements of a statically allocated array
|
/// Returns the number of elements of a statically allocated array
|
||||||
|
#if !defined(COMPILER_CLANG)
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
size_t elems(T (&)[N])
|
size_t elems(T (&)[N])
|
||||||
{ return N; }
|
{ return N; }
|
||||||
|
#else
|
||||||
|
#define elems(x) (sizeof(x) / 0[x])
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template<class T, class...Args>
|
template<class T, class...Args>
|
||||||
@ -37,4 +43,4 @@ make_unique(Args&&... args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // __TYPES_HPP
|
#endif
|
||||||
|
@ -48,6 +48,12 @@ namespace detail {
|
|||||||
CHECK_HARD (v < std::numeric_limits<V>::max () / 2);
|
CHECK_HARD (v < std::numeric_limits<V>::max () / 2);
|
||||||
return static_cast<T> (v);
|
return static_cast<T> (v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, typename V>
|
||||||
|
T
|
||||||
|
_sign_cast (const typename std::enable_if<std::is_same<T, V>::value, V>::type v)
|
||||||
|
{ return v; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safely cast a numeric type to its (un)signed counterpart, aborting if the
|
/// Safely cast a numeric type to its (un)signed counterpart, aborting if the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user