Просмотр исходного кода

enum:
* remove unused functions
* avoid errors due to narrowing conversions

Michele Caini 4 лет назад
Родитель
Сommit
eec867bc9e
2 измененных файлов с 7 добавлено и 19 удалено
  1. 4 18
      src/entt/core/enum.hpp
  2. 3 1
      test/entt/core/enum.cpp

+ 4 - 18
src/entt/core/enum.hpp

@@ -37,21 +37,21 @@ inline constexpr bool enum_as_bitmask_v = enum_as_bitmask<Type>::value;
 template<typename Type>
 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
 operator|(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
-    return Type{static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs)};
+    return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
 }
 
 /*! @copydoc operator| */
 template<typename Type>
 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
 operator&(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
-    return Type{static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs)};
+    return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
 }
 
 /*! @copydoc operator| */
 template<typename Type>
 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
 operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
-    return Type{static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs)};
+    return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
 }
 
 /**
@@ -64,7 +64,7 @@ operator^(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
 template<typename Type>
 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
 operator~(const Type value) ENTT_NOEXCEPT {
-    return Type{~static_cast<std::underlying_type_t<Type>>(value)};
+    return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
 }
 
 /*! @copydoc operator~ */
@@ -95,18 +95,4 @@ operator^=(Type &lhs, const Type rhs) ENTT_NOEXCEPT {
     return (lhs = (lhs ^ rhs));
 }
 
-/*! @copydoc operator| */
-template<typename Type>
-[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
-operator==(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
-    return (static_cast<std::underlying_type_t<Type>>(lhs) == static_cast<std::underlying_type_t<Type>>(rhs));
-}
-
-/*! @copydoc operator| */
-template<typename Type>
-[[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
-operator!=(const Type lhs, const Type rhs) ENTT_NOEXCEPT {
-    return !(lhs == rhs);
-}
-
 #endif

+ 3 - 1
test/entt/core/enum.cpp

@@ -1,3 +1,4 @@
+#include <cstddef>
 #include <gtest/gtest.h>
 #include <entt/core/enum.hpp>
 #include <entt/core/type_traits.hpp>
@@ -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