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

core: tag is no longer deprecated (close #457)

Michele Caini 5 лет назад
Родитель
Сommit
8151fbcb2e
2 измененных файлов с 27 добавлено и 10 удалено
  1. 19 2
      docs/md/core.md
  2. 8 8
      src/entt/core/type_traits.hpp

+ 19 - 2
docs/md/core.md

@@ -20,6 +20,7 @@
   * [Type traits](#type-traits)
     * [Member class type](#member-class-type)
     * [Integral constant](#integral-constant)
+    * [Tag](#tag)
 <!--
 @endcond TURN_OFF_DOXYGEN
 -->
@@ -223,7 +224,7 @@ specializations such as:
 ```cpp
 template<typename Type>
 struct entt::type_info<Type, std::void_d<decltype(Type::custom_id())>> {
-    static constexpr ENTT_ID_TYPE id() ENTT_NOEXCEPT {
+    static constexpr entt::id_type id() ENTT_NOEXCEPT {
         return Type::custom_id();
     }
 };
@@ -294,7 +295,7 @@ specializations such as:
 ```cpp
 template<typename Type>
 struct entt::type_index<Type, std::void_d<decltype(Type::index())>> {
-    static id_type value() ENTT_NOEXCEPT {
+    static entt::id_type value() ENTT_NOEXCEPT {
         return Type::index();
     }
 };
@@ -341,3 +342,19 @@ as human-readable _names_ where actual types would be required otherwise:
 constexpr auto enemy_tag = entt::integral_constant<"enemy"_hs>;
 registry.emplace<enemy_tag>(entity);
 ```
+
+### Tag
+
+Since `id_type` is very important and widely used in `EnTT`, there is a more
+user-friendly shortcut for the creation of integral constants based on it.<br/>
+This shortcut is the alias template `entt::tag`.
+
+If used in combination with hashed strings, it helps to use human-readable names
+where types would be required otherwise. As an example:
+
+```cpp
+registry.assign<entt::tag<"enemy"_hs>>(entity);
+```
+
+However, this isn't the only permitted use. Literally any value convertible to
+`id_type` is a good candidate, such as the named constants of an unscoped enum.

+ 8 - 8
src/entt/core/type_traits.hpp

@@ -21,6 +21,14 @@ template<auto Value>
 using integral_constant = std::integral_constant<decltype(Value), Value>;
 
 
+/**
+ * @brief Alias template to ease the creation of named values.
+ * @tparam Value A constant value at least convertible to `id_type`.
+ */
+template<id_type Value>
+using tag = integral_constant<Value>;
+
+
 /**
  * @brief Utility class to disambiguate overloaded functions.
  * @tparam N Number of choices available.
@@ -210,14 +218,6 @@ template<typename Member>
 using member_class_t = typename member_class<Member>::type;
 
 
-/**
- * @brief Alias template to ease the creation of named values.
- * @tparam Value A constant value at least convertible to `id_type`.
- */
-template<id_type Value>
-using tag [[deprecated("use entt::integral_constant instead")]] = integral_constant<Value>;
-
-
 }