Преглед изворни кода

ident/family: change names for consistency

Michele Caini пре 3 година
родитељ
комит
14d213d13e
5 измењених фајлова са 42 додато и 65 уклоњено
  1. 11 11
      docs/md/core.md
  2. 2 2
      src/entt/core/family.hpp
  3. 10 33
      src/entt/core/ident.hpp
  4. 7 7
      test/entt/core/family.cpp
  5. 12 12
      test/entt/core/ident.cpp

+ 11 - 11
docs/md/core.md

@@ -784,19 +784,19 @@ that fully embraces what the modern C++ has to offer.
 ## Compile-time generator
 
 To generate sequential numeric identifiers at compile-time, `EnTT` offers the
-`identifier` class template:
+`ident` class template:
 
 ```cpp
 // defines the identifiers for the given types
-using id = entt::identifier<a_type, another_type>;
+using id = entt::ident<a_type, another_type>;
 
 // ...
 
 switch(a_type_identifier) {
-case id::type<a_type>:
+case id::value<a_type>:
     // ...
     break;
-case id::type<another_type>:
+case id::value<another_type>:
     // ...
     break;
 default:
@@ -804,7 +804,7 @@ default:
 }
 ```
 
-This is all what this class template has to offer: a `type` inline variable that
+This is what this class template has to offer: a `value` inline variable that
 contains a numeric identifier for the given type. It can be used in any context
 where constant expressions are required.
 
@@ -816,9 +816,9 @@ the other identifiers unchanged:
 ```cpp
 template<typename> struct ignore_type {};
 
-using id = entt::identifier<
+using id = entt::ident<
     a_type_still_valid,
-    ignore_type<a_type_no_longer_valid>,
+    ignore_type<no_longer_valid_type>,
     another_type_still_valid
 >;
 ```
@@ -836,12 +836,12 @@ using id = entt::family<struct my_tag>;
 
 // ...
 
-const auto a_type_id = id::type<a_type>;
-const auto another_type_id = id::type<another_type>;
+const auto a_type_id = id::value<a_type>;
+const auto another_type_id = id::value<another_type>;
 ```
 
-This is all what a _family_ has to offer: a `type` inline variable that contains
-a numeric identifier for the given type.<br/>
+This is what a _family_ has to offer: a `value` inline variable that contains a
+numeric identifier for the given type.<br/>
 The generator is customizable, so as to get different _sequences_ for different
 purposes if needed.
 

+ 2 - 2
src/entt/core/family.hpp

@@ -19,12 +19,12 @@ class family {
 
 public:
     /*! @brief Unsigned integer type. */
-    using family_type = id_type;
+    using value_type = id_type;
 
     /*! @brief Statically generated unique identifier for the given type. */
     template<typename... Type>
     // at the time I'm writing, clang crashes during compilation if auto is used instead of family_type
-    inline static const family_type type = identifier++;
+    inline static const value_type value = identifier++;
 };
 
 } // namespace entt

+ 10 - 33
src/entt/core/ident.hpp

@@ -11,47 +11,24 @@
 namespace entt {
 
 /**
- * @brief Types identifiers.
- *
- * Variable template used to generate identifiers at compile-time for the given
- * types. Use the `get` member function to know what's the identifier associated
- * to the specific type.
- *
- * @note
- * Identifiers are constant expression and can be used in any context where such
- * an expression is required. As an example:
- * @code{.cpp}
- * using id = entt::identifier<a_type, another_type>;
- *
- * switch(a_type_identifier) {
- * case id::type<a_type>:
- *     // ...
- *     break;
- * case id::type<another_type>:
- *     // ...
- *     break;
- * default:
- *     // ...
- * }
- * @endcode
- *
- * @tparam Types List of types for which to generate identifiers.
+ * @brief Type integral identifiers.
+ * @tparam Type List of types for which to generate identifiers.
  */
-template<typename... Types>
-class identifier {
-    template<typename Type, std::size_t... Index>
+template<typename... Type>
+class ident {
+    template<typename Curr, std::size_t... Index>
     [[nodiscard]] static constexpr id_type get(std::index_sequence<Index...>) ENTT_NOEXCEPT {
-        static_assert((std::is_same_v<Type, Types> || ...), "Invalid type");
-        return (0 + ... + (std::is_same_v<Type, type_list_element_t<Index, type_list<std::decay_t<Types>...>>> ? id_type{Index} : id_type{}));
+        static_assert((std::is_same_v<Curr, Type> || ...), "Invalid type");
+        return (0 + ... + (std::is_same_v<Curr, type_list_element_t<Index, type_list<std::decay_t<Type>...>>> ? id_type{Index} : id_type{}));
     }
 
 public:
     /*! @brief Unsigned integer type. */
-    using identifier_type = id_type;
+    using value_type = id_type;
 
     /*! @brief Statically generated unique identifier for the given type. */
-    template<typename Type>
-    static constexpr identifier_type type = get<std::decay_t<Type>>(std::index_sequence_for<Types...>{});
+    template<typename Curr>
+    static constexpr value_type value = get<std::decay_t<Curr>>(std::index_sequence_for<Type...>{});
 };
 
 } // namespace entt

+ 7 - 7
test/entt/core/family.cpp

@@ -5,10 +5,10 @@ using a_family = entt::family<struct a_family_type>;
 using another_family = entt::family<struct another_family_type>;
 
 TEST(Family, Functionalities) {
-    auto t1 = a_family::type<int>;
-    auto t2 = a_family::type<int>;
-    auto t3 = a_family::type<char>;
-    auto t4 = another_family::type<double>;
+    auto t1 = a_family::value<int>;
+    auto t2 = a_family::value<int>;
+    auto t3 = a_family::value<char>;
+    auto t4 = another_family::value<double>;
 
     ASSERT_EQ(t1, t2);
     ASSERT_NE(t1, t3);
@@ -16,7 +16,7 @@ TEST(Family, Functionalities) {
 }
 
 TEST(Family, Uniqueness) {
-    ASSERT_NE(a_family::type<int>, a_family::type<int &>);
-    ASSERT_NE(a_family::type<int>, a_family::type<int &&>);
-    ASSERT_NE(a_family::type<int>, a_family::type<const int &>);
+    ASSERT_NE(a_family::value<int>, a_family::value<int &>);
+    ASSERT_NE(a_family::value<int>, a_family::value<int &&>);
+    ASSERT_NE(a_family::value<int>, a_family::value<const int &>);
 }

+ 12 - 12
test/entt/core/ident.cpp

@@ -5,27 +5,27 @@
 struct a_type {};
 struct another_type {};
 
-TEST(Identifier, Uniqueness) {
-    using id = entt::identifier<a_type, another_type>;
+TEST(Ident, Uniqueness) {
+    using id = entt::ident<a_type, another_type>;
     constexpr a_type an_instance;
     constexpr another_type another_instance;
 
-    ASSERT_NE(id::type<a_type>, id::type<another_type>);
-    ASSERT_EQ(id::type<a_type>, id::type<decltype(an_instance)>);
-    ASSERT_NE(id::type<a_type>, id::type<decltype(another_instance)>);
-    ASSERT_EQ(id::type<a_type>, id::type<a_type>);
-    ASSERT_EQ(id::type<another_type>, id::type<another_type>);
+    ASSERT_NE(id::value<a_type>, id::value<another_type>);
+    ASSERT_EQ(id::value<a_type>, id::value<decltype(an_instance)>);
+    ASSERT_NE(id::value<a_type>, id::value<decltype(another_instance)>);
+    ASSERT_EQ(id::value<a_type>, id::value<a_type>);
+    ASSERT_EQ(id::value<another_type>, id::value<another_type>);
 
     // test uses in constant expressions
-    switch(id::type<another_type>) {
-    case id::type<a_type>:
+    switch(id::value<another_type>) {
+    case id::value<a_type>:
         FAIL();
-    case id::type<another_type>:
+    case id::value<another_type>:
         SUCCEED();
     }
 }
 
 TEST(Identifier, SingleType) {
-    using id = entt::identifier<a_type>;
-    [[maybe_unused]] std::integral_constant<id::identifier_type, id::type<a_type>> ic;
+    using id = entt::ident<a_type>;
+    [[maybe_unused]] std::integral_constant<id::value_type, id::value<a_type>> ic;
 }