From 8151fbcb2eab56b45e482417c8397b90c04b3872 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 6 Apr 2020 23:21:17 +0200 Subject: [PATCH] core: tag is no longer deprecated (close #457) --- docs/md/core.md | 21 +++++++++++++++++++-- src/entt/core/type_traits.hpp | 16 ++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/md/core.md b/docs/md/core.md index 69df83e9a..ee0fe0e1c 100644 --- a/docs/md/core.md +++ b/docs/md/core.md @@ -20,6 +20,7 @@ * [Type traits](#type-traits) * [Member class type](#member-class-type) * [Integral constant](#integral-constant) + * [Tag](#tag) @@ -223,7 +224,7 @@ specializations such as: ```cpp template struct entt::type_info> { - 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 struct entt::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(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.
+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>(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. diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index a5e80c26c..f90b8e5fe 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -21,6 +21,14 @@ template using integral_constant = std::integral_constant; +/** + * @brief Alias template to ease the creation of named values. + * @tparam Value A constant value at least convertible to `id_type`. + */ +template +using tag = integral_constant; + + /** * @brief Utility class to disambiguate overloaded functions. * @tparam N Number of choices available. @@ -210,14 +218,6 @@ template using member_class_t = typename member_class::type; -/** - * @brief Alias template to ease the creation of named values. - * @tparam Value A constant value at least convertible to `id_type`. - */ -template -using tag [[deprecated("use entt::integral_constant instead")]] = integral_constant; - - }