Kaynağa Gözat

entity: bind to_integral to entt_traits instead of a specific enum class

Michele Caini 5 yıl önce
ebeveyn
işleme
29d4846de7
2 değiştirilmiş dosya ile 14 ekleme ve 13 silme
  1. 2 13
      src/entt/core/type_traits.hpp
  2. 12 0
      src/entt/entity/entity.hpp

+ 2 - 13
src/entt/core/type_traits.hpp

@@ -242,22 +242,11 @@ using member_class_t = typename member_class<Member>::type;
 
 #define ENTT_OPAQUE_TYPE(clazz, type)\
     /**\
-       @brief Defines an enum class to use for opaque identifiers and a\
-       dedicate `to_integral` function to convert the identifiers to their\
-       underlying type.\
+       @brief Defines an enum class to use for opaque identifiers.\
        @param clazz The name to use for the enum class.\
        @param type The underlying type for the enum class.\
      */\
-    enum class clazz: type {};\
-    /**\
-       @brief Converts an opaque type value to its underlying type.\
-       @param id The value to convert.\
-       @return The integral representation of the given value.\
-     */\
-    [[nodiscard]] constexpr auto to_integral(const clazz id) ENTT_NOEXCEPT {\
-        return static_cast<std::underlying_type_t<clazz>>(id);\
-    }\
-    static_assert(true)
+    enum class clazz: type {}
 
 
 #endif

+ 12 - 0
src/entt/entity/entity.hpp

@@ -110,6 +110,18 @@ struct entt_traits<std::uint64_t> {
 };
 
 
+/**
+ * @brief Converts an entity type to its underlying type.
+ * @tparam Entity The value type.
+ * @param entity The value to convert.
+ * @return The integral representation of the given value.
+ */
+template<typename Entity>
+[[nodiscard]] constexpr auto to_integral(const Entity entity) ENTT_NOEXCEPT {
+    return static_cast<typename entt_traits<Entity>::entity_type>(entity);
+}
+
+
 /**
  * @cond TURN_OFF_DOXYGEN
  * Internal details not to be documented.