diff options
author | Chris Robinson <[email protected]> | 2019-05-28 08:49:53 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-28 08:49:53 -0700 |
commit | 7ce2b632f51292c26014ad2efeb4b5429c3bf04f (patch) | |
tree | 1e7df6544e3263ab079643363405d148462df816 | |
parent | aa4b6afad64e3a1e4c5a55652494a8970a4c2fbc (diff) |
Simplify template type requirement checking
-rw-r--r-- | common/albyte.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/common/albyte.h b/common/albyte.h index f9230005..d1459e96 100644 --- a/common/albyte.h +++ b/common/albyte.h @@ -11,20 +11,22 @@ namespace al { */ enum class byte : unsigned char { }; -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> +#define REQUIRES(...) typename std::enable_if<(__VA_ARGS__),int>::type = 0 + +template<typename T, REQUIRES(std::is_integral<T>::value)> inline constexpr T to_integer(al::byte b) noexcept { return T(b); } -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> +template<typename T, REQUIRES(std::is_integral<T>::value)> inline constexpr al::byte operator<<(al::byte lhs, T rhs) noexcept { return al::byte(to_integer<unsigned int>(lhs) << rhs); } -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> +template<typename T, REQUIRES(std::is_integral<T>::value)> inline constexpr al::byte operator>>(al::byte lhs, T rhs) noexcept { return al::byte(to_integer<unsigned int>(lhs) >> rhs); } #define AL_DECL_OP(op) \ -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> \ +template<typename T, REQUIRES(std::is_integral<T>::value)> \ inline constexpr al::byte operator op (al::byte lhs, T rhs) noexcept \ { return al::byte(to_integer<unsigned int>(lhs) op rhs); } \ inline constexpr al::byte operator op (al::byte lhs, al::byte rhs) noexcept \ @@ -40,16 +42,16 @@ inline constexpr al::byte operator~(al::byte b) noexcept { return al::byte(~to_integer<unsigned int>(b)); } -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> +template<typename T, REQUIRES(std::is_integral<T>::value)> inline al::byte& operator<<=(al::byte &lhs, T rhs) noexcept { lhs = lhs << rhs; return lhs; } -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> +template<typename T, REQUIRES(std::is_integral<T>::value)> inline al::byte& operator>>=(al::byte &lhs, T rhs) noexcept { lhs = lhs >> rhs; return lhs; } #define AL_DECL_OP(op) \ -template<typename T, typename std::enable_if<std::is_integral<T>::value,int>::type = 0> \ +template<typename T, REQUIRES(std::is_integral<T>::value)> \ inline al::byte& operator op##= (al::byte &lhs, T rhs) noexcept \ { lhs = lhs op rhs; return lhs; } \ inline al::byte& operator op##= (al::byte &lhs, al::byte rhs) noexcept \ @@ -61,6 +63,8 @@ AL_DECL_OP(^) #undef AL_DECL_OP +#undef REQUIRES + } // namespace al #endif /* AL_BYTE_H */ |