From fb26da1cb091711c000bde07b32732b4b3956ae7 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 17 Apr 2021 16:32:15 +0300 Subject: [PATCH] bs_t<>: create BitSetEnum concept Try concepts instead of SFINAE. --- Utilities/bit_set.h | 44 ++++++++++++--------- rpcs3/cmake_modules/ConfigureCompiler.cmake | 4 ++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Utilities/bit_set.h b/Utilities/bit_set.h index 28e3099ddd..6daf762c2d 100644 --- a/Utilities/bit_set.h +++ b/Utilities/bit_set.h @@ -26,10 +26,16 @@ Intersection (&) and symmetric difference (^) is also available. #include "Utilities/StrFmt.h" template +concept BitSetEnum = std::is_enum_v && requires(T x) +{ + T::__bitset_enum_max; +}; + +template class atomic_bs_t; // Bitset type for enum class with available bits [0, T::__bitset_enum_max) -template +template class bs_t final { public: @@ -165,70 +171,70 @@ public: }; // Unary '+' operator: promote plain enum value to bitset value -template +template constexpr bs_t operator +(T bit) { return bs_t(bit); } // Binary '+' operator: bitset union -template -constexpr std::enable_if_t, U>, bs_t> operator +(T lhs, const U& rhs) +template requires (std::is_constructible_v, U>) +constexpr bs_t operator +(T lhs, const U& rhs) { return bs_t(lhs) + bs_t(rhs); } // Binary '+' operator: bitset union -template -constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator +(const U& lhs, T rhs) +template requires (std::is_constructible_v, U> && !std::is_enum_v) +constexpr bs_t operator +(const U& lhs, T rhs) { return bs_t(lhs) + bs_t(rhs); } // Binary '-' operator: bitset difference -template -constexpr std::enable_if_t, U>, bs_t> operator -(T lhs, const U& rhs) +template requires (std::is_constructible_v, U>) +constexpr bs_t operator -(T lhs, const U& rhs) { return bs_t(lhs) - bs_t(rhs); } // Binary '-' operator: bitset difference -template -constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator -(const U& lhs, T rhs) +template requires (std::is_constructible_v, U> && !std::is_enum_v) +constexpr bs_t operator -(const U& lhs, T rhs) { return bs_t(lhs) - bs_t(rhs); } // Binary '&' operator: bitset intersection -template -constexpr std::enable_if_t, U>, bs_t> operator &(T lhs, const U& rhs) +template requires (std::is_constructible_v, U>) +constexpr bs_t operator &(T lhs, const U& rhs) { return bs_t(lhs) & bs_t(rhs); } // Binary '&' operator: bitset intersection -template -constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator &(const U& lhs, T rhs) +template requires (std::is_constructible_v, U> && !std::is_enum_v) +constexpr bs_t operator &(const U& lhs, T rhs) { return bs_t(lhs) & bs_t(rhs); } // Binary '^' operator: bitset symmetric difference -template -constexpr std::enable_if_t, U>, bs_t> operator ^(T lhs, const U& rhs) +template requires (std::is_constructible_v, U>) +constexpr bs_t operator ^(T lhs, const U& rhs) { return bs_t(lhs) ^ bs_t(rhs); } // Binary '^' operator: bitset symmetric difference -template -constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator ^(const U& lhs, T rhs) +template requires (std::is_constructible_v, U> && !std::is_enum_v) +constexpr bs_t operator ^(const U& lhs, T rhs) { return bs_t(lhs) ^ bs_t(rhs); } // Atomic bitset specialization with optimized operations -template +template class atomic_bs_t : public atomic_t<::bs_t> { // Corresponding bitset type diff --git a/rpcs3/cmake_modules/ConfigureCompiler.cmake b/rpcs3/cmake_modules/ConfigureCompiler.cmake index 72fc0e7767..f7f2aae47c 100644 --- a/rpcs3/cmake_modules/ConfigureCompiler.cmake +++ b/rpcs3/cmake_modules/ConfigureCompiler.cmake @@ -27,6 +27,10 @@ else() add_compile_options(-fstack-protector) add_compile_options(-msse -msse2 -mcx16) + if ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.1)) + add_compile_options(-fconcepts) + endif() + add_compile_options(-Werror=old-style-cast) add_compile_options(-Werror=sign-compare) add_compile_options(-Werror=reorder)