From eec867bc9e846ad220d159ccdc3baeb31a6c092a Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 31 Jan 2022 08:44:24 +0100 Subject: [PATCH] enum: * remove unused functions * avoid errors due to narrowing conversions --- src/entt/core/enum.hpp | 22 ++++------------------ test/entt/core/enum.cpp | 4 +++- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/entt/core/enum.hpp b/src/entt/core/enum.hpp index 359f9436f..01e3d894a 100644 --- a/src/entt/core/enum.hpp +++ b/src/entt/core/enum.hpp @@ -37,21 +37,21 @@ inline constexpr bool enum_as_bitmask_v = enum_as_bitmask::value; template [[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> operator|(const Type lhs, const Type rhs) ENTT_NOEXCEPT { - return Type{static_cast>(lhs) | static_cast>(rhs)}; + return static_cast(static_cast>(lhs) | static_cast>(rhs)); } /*! @copydoc operator| */ template [[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> operator&(const Type lhs, const Type rhs) ENTT_NOEXCEPT { - return Type{static_cast>(lhs) & static_cast>(rhs)}; + return static_cast(static_cast>(lhs) & static_cast>(rhs)); } /*! @copydoc operator| */ template [[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT { - return Type{static_cast>(lhs) ^ static_cast>(rhs)}; + return static_cast(static_cast>(lhs) ^ static_cast>(rhs)); } /** @@ -64,7 +64,7 @@ operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT { template [[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> operator~(const Type value) ENTT_NOEXCEPT { - return Type{~static_cast>(value)}; + return static_cast(~static_cast>(value)); } /*! @copydoc operator~ */ @@ -95,18 +95,4 @@ operator^=(Type &lhs, const Type rhs) ENTT_NOEXCEPT { return (lhs = (lhs ^ rhs)); } -/*! @copydoc operator| */ -template -[[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> -operator==(const Type lhs, const Type rhs) ENTT_NOEXCEPT { - return (static_cast>(lhs) == static_cast>(rhs)); -} - -/*! @copydoc operator| */ -template -[[nodiscard]] constexpr std::enable_if_t && entt::enum_as_bitmask_v, Type> -operator!=(const Type lhs, const Type rhs) ENTT_NOEXCEPT { - return !(lhs == rhs); -} - #endif diff --git a/test/entt/core/enum.cpp b/test/entt/core/enum.cpp index 8dd614cdf..65b8fb605 100644 --- a/test/entt/core/enum.cpp +++ b/test/entt/core/enum.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,7 +10,8 @@ enum class detected { _entt_enum_as_bitmask }; -enum class registered { +// small type on purpose +enum class registered : std::uint8_t { foo = 0x01, bar = 0x02, quux = 0x04