From 0c7a7e1bd6b3636f8daf276a3a4dd2bfe364e68b Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 10 Apr 2019 01:00:50 +0000 Subject: [PATCH] compat.h: Factor some repeated conditional_t statements into a new take_sign_t git-svn-id: https://svn.eduke32.com/eduke32@7559 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/compat.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 502611640..86e3c5a06 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -748,6 +748,11 @@ template using make_unsigned_t = typename std::make_unsigned::type; # endif +# ifdef HAVE_CXX11_HEADERS +template +using take_sign_t = conditional_t< is_signed::value, make_signed_t, make_unsigned_t >; +# endif + template struct integers_of_size { }; template <> @@ -955,35 +960,35 @@ static FORCE_INLINE CONSTEXPR uint64_t B_SWAP64_impl(uint64_t value) /* The purpose of B_PASS* as functions, as opposed to macros, is to prevent them from being used as lvalues. */ #if CXXSTD >= 2011 template -static FORCE_INLINE CONSTEXPR conditional_t::value, int16_t, uint16_t> B_SWAP16(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP16(T x) { - return static_cast< conditional_t::value, int16_t, uint16_t> >(B_SWAP16_impl(static_cast(x))); + return static_cast< take_sign_t >(B_SWAP16_impl(static_cast(x))); } template -static FORCE_INLINE CONSTEXPR conditional_t::value, int32_t, uint32_t> B_SWAP32(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP32(T x) { - return static_cast< conditional_t::value, int32_t, uint32_t> >(B_SWAP32_impl(static_cast(x))); + return static_cast< take_sign_t >(B_SWAP32_impl(static_cast(x))); } template -static FORCE_INLINE CONSTEXPR conditional_t::value, int64_t, uint64_t> B_SWAP64(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_SWAP64(T x) { - return static_cast< conditional_t::value, int64_t, uint64_t> >(B_SWAP64_impl(static_cast(x))); + return static_cast< take_sign_t >(B_SWAP64_impl(static_cast(x))); } template -static FORCE_INLINE CONSTEXPR conditional_t::value, int16_t, uint16_t> B_PASS16(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_PASS16(T x) { - return static_cast< conditional_t::value, int16_t, uint16_t> >(x); + return static_cast< take_sign_t >(x); } template -static FORCE_INLINE CONSTEXPR conditional_t::value, int32_t, uint32_t> B_PASS32(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_PASS32(T x) { - return static_cast< conditional_t::value, int32_t, uint32_t> >(x); + return static_cast< take_sign_t >(x); } template -static FORCE_INLINE CONSTEXPR conditional_t::value, int64_t, uint64_t> B_PASS64(T x) +static FORCE_INLINE CONSTEXPR take_sign_t B_PASS64(T x) { - return static_cast< conditional_t::value, int64_t, uint64_t> >(x); + return static_cast< take_sign_t >(x); } #else #define B_SWAP16(x) B_SWAP16_impl(x)