From fb4cef5b61639c507e6c5740cc5973d0d79ba673 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 11 Nov 2020 21:43:27 +1100 Subject: Replace std::enable_if with requires Introduce some concepts for enum and flags handling, goodbye and thanks for all the fish std::enable_if. --- src/flags.hh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/flags.hh') diff --git a/src/flags.hh b/src/flags.hh index 6b701016..6d4764f3 100644 --- a/src/flags.hh +++ b/src/flags.hh @@ -12,21 +12,18 @@ template constexpr bool with_bit_ops(Meta::Type) { return false; } template -using UnderlyingType = std::underlying_type_t; - -template -using EnableIfWithBitOps = std::enable_if_t{}), T>; +concept WithBitOps = with_bit_ops(Meta::Type{}); -template -using EnableIfWithoutBitOps = std::enable_if_t{}), T>; +template +using UnderlyingType = std::underlying_type_t; -template> +template constexpr Flags operator|(Flags lhs, Flags rhs) { return (Flags)((UnderlyingType) lhs | (UnderlyingType) rhs); } -template> +template constexpr Flags& operator|=(Flags& lhs, Flags rhs) { (UnderlyingType&) lhs |= (UnderlyingType) rhs; @@ -45,32 +42,32 @@ struct TestableFlags constexpr bool operator!=(const TestableFlags& other) const { return value != other.value; } }; -template> +template constexpr TestableFlags operator&(Flags lhs, Flags rhs) { return { (Flags)((UnderlyingType) lhs & (UnderlyingType) rhs) }; } -template> +template constexpr Flags& operator&=(Flags& lhs, Flags rhs) { (UnderlyingType&) lhs &= (UnderlyingType) rhs; return lhs; } -template> +template constexpr Flags operator~(Flags lhs) { return (Flags)(~(UnderlyingType)lhs); } -template> +template constexpr Flags operator^(Flags lhs, Flags rhs) { return (Flags)((UnderlyingType) lhs ^ (UnderlyingType) rhs); } -template> +template constexpr Flags& operator^=(Flags& lhs, Flags rhs) { (UnderlyingType&) lhs ^= (UnderlyingType) rhs; -- cgit v1.2.3