Browse Source

type_info: name rollback, hash_code -> hash (why should I introduce a breaking change to match a terrible name from the standard library after all?)

Michele Caini 4 years ago
parent
commit
fb3252732b

+ 1 - 1
docs/md/core.md

@@ -494,7 +494,7 @@ These are the information made available by this object:
 * The hash value associated with a given type:
 
   ```cpp
-  auto hash = entt::type_id<a_type>().hash_code();
+  auto hash = entt::type_id<a_type>().hash();
   ```
 
   This is also an alias for the following:

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

@@ -393,7 +393,7 @@ Type any_cast(basic_any<Len, Align> &&data) ENTT_NOEXCEPT {
 /*! @copydoc any_cast */
 template<typename Type, std::size_t Len, std::size_t Align>
 const Type * any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
-    if(data->type().hash_code() == type_hash<std::remove_const_t<std::remove_reference_t<Type>>>::value()) {
+    if(data->type().hash() == type_hash<std::remove_const_t<std::remove_reference_t<Type>>>::value()) {
         return static_cast<const Type *>(data->data());
     }
 
@@ -404,7 +404,7 @@ const Type * any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
 /*! @copydoc any_cast */
 template<typename Type, std::size_t Len, std::size_t Align>
 Type * any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
-    if(data->type().hash_code() == type_hash<std::remove_const_t<std::remove_reference_t<Type>>>::value()) {
+    if(data->type().hash() == type_hash<std::remove_const_t<std::remove_reference_t<Type>>>::value()) {
         // last attempt to make wrappers for const references return their values
         return static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data());
     }

+ 1 - 1
src/entt/core/type_info.hpp

@@ -194,7 +194,7 @@ struct type_info final {
      * @brief Type hash.
      * @return Type hash.
      */
-    [[nodiscard]] constexpr id_type hash_code() const ENTT_NOEXCEPT {
+    [[nodiscard]] constexpr id_type hash() const ENTT_NOEXCEPT {
         return identifier;
     }
 

+ 4 - 4
src/entt/entity/registry.hpp

@@ -183,14 +183,14 @@ public:
      * empty and thus invalid element otherwise.
      */
     poly_storage & storage(const type_info info) {
-        auto it = std::find_if(pools.begin(), pools.end(), [info](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash_code() == info.hash_code(); });
+        auto it = std::find_if(pools.begin(), pools.end(), [info](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash() == info.hash(); });
         ENTT_ASSERT(it != pools.end(), "Storage not available");
         return it->poly;
     }
 
     /*! @copydoc storage */
     const poly_storage & storage(const type_info info) const {
-        auto it = std::find_if(pools.cbegin(), pools.cend(), [info](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash_code() == info.hash_code(); });
+        auto it = std::find_if(pools.cbegin(), pools.cend(), [info](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash() == info.hash(); });
         ENTT_ASSERT(it != pools.cend(), "Storage not available");
         return it->poly;
     }
@@ -1167,12 +1167,12 @@ public:
         std::vector<const basic_common_type *> filter(std::distance(from, to));
 
         std::transform(first, last, component.begin(), [this](const auto ctype) {
-            const auto it = std::find_if(pools.cbegin(), pools.cend(), [ctype](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash_code() == ctype; });
+            const auto it = std::find_if(pools.cbegin(), pools.cend(), [ctype](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash() == ctype; });
             return it == pools.cend() ? nullptr : it->pool.get();
         });
 
         std::transform(from, to, filter.begin(), [this](const auto ctype) {
-            const auto it = std::find_if(pools.cbegin(), pools.cend(), [ctype](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash_code() == ctype; });
+            const auto it = std::find_if(pools.cbegin(), pools.cend(), [ctype](auto &&pdata) { return pdata.poly && pdata.poly->value_type().hash() == ctype; });
             return it == pools.cend() ? nullptr : it->pool.get();
         });
 

+ 4 - 4
test/entt/core/type_info.cpp

@@ -62,7 +62,7 @@ TEST(TypeInfo, Functionalities) {
     ASSERT_TRUE(info == info);
     ASSERT_FALSE(info != info);
 
-    ASSERT_EQ(info.hash_code(), entt::type_hash<int>::value());
+    ASSERT_EQ(info.hash(), entt::type_hash<int>::value());
     ASSERT_EQ(info.name(), entt::type_name<int>::value());
 
     ASSERT_TRUE(info);
@@ -72,15 +72,15 @@ TEST(TypeInfo, Functionalities) {
     empty = info;
 
     ASSERT_TRUE(empty);
-    ASSERT_EQ(empty.hash_code(), info.hash_code());
+    ASSERT_EQ(empty.hash(), info.hash());
 
     empty = {};
 
     ASSERT_FALSE(empty);
-    ASSERT_NE(empty.hash_code(), info.hash_code());
+    ASSERT_NE(empty.hash(), info.hash());
 
     empty = std::move(info);
 
     ASSERT_TRUE(empty);
-    ASSERT_EQ(empty.hash_code(), info.hash_code());
+    ASSERT_EQ(empty.hash(), info.hash());
 }

+ 10 - 10
test/entt/entity/registry.cpp

@@ -79,7 +79,7 @@ TEST(Registry, Context) {
     auto count = 0;
 
     registry.ctx([&count](auto info) {
-        ASSERT_EQ(info.hash_code(), entt::type_hash<char>::value());
+        ASSERT_EQ(info.hash(), entt::type_hash<char>::value());
         ++count;
     });
 
@@ -1881,9 +1881,9 @@ TEST(Registry, Visit) {
     bool hasType[3]{};
 
     registry.visit([&hasType](auto info) {
-        hasType[0] = hasType[0] || (info.hash_code() == entt::type_hash<int>::value());
-        hasType[1] = hasType[1] || (info.hash_code() == entt::type_hash<double>::value());
-        hasType[2] = hasType[2] || (info.hash_code() == entt::type_hash<char>::value());
+        hasType[0] = hasType[0] || (info.hash() == entt::type_hash<int>::value());
+        hasType[1] = hasType[1] || (info.hash() == entt::type_hash<double>::value());
+        hasType[2] = hasType[2] || (info.hash() == entt::type_hash<char>::value());
     });
 
     ASSERT_TRUE(hasType[0] && hasType[1] && hasType[2]);
@@ -1891,9 +1891,9 @@ TEST(Registry, Visit) {
     hasType[0] = hasType[1] = hasType[2] = false;
 
     registry.visit(entity, [&hasType](auto info) {
-        hasType[0] = hasType[0] || (info.hash_code() == entt::type_hash<int>::value());
-        hasType[1] = hasType[1] || (info.hash_code() == entt::type_hash<double>::value());
-        hasType[2] = hasType[2] || (info.hash_code() == entt::type_hash<char>::value());
+        hasType[0] = hasType[0] || (info.hash() == entt::type_hash<int>::value());
+        hasType[1] = hasType[1] || (info.hash() == entt::type_hash<double>::value());
+        hasType[2] = hasType[2] || (info.hash() == entt::type_hash<char>::value());
     });
 
     ASSERT_TRUE(hasType[0] && !hasType[1] && hasType[2]);
@@ -1901,9 +1901,9 @@ TEST(Registry, Visit) {
     hasType[0] = hasType[2] = false;
 
     registry.visit(other, [&hasType](auto info) {
-        hasType[0] = hasType[0] || (info.hash_code() == entt::type_hash<int>::value());
-        hasType[1] = hasType[1] || (info.hash_code() == entt::type_hash<double>::value());
-        hasType[2] = hasType[2] || (info.hash_code() == entt::type_hash<char>::value());
+        hasType[0] = hasType[0] || (info.hash() == entt::type_hash<int>::value());
+        hasType[1] = hasType[1] || (info.hash() == entt::type_hash<double>::value());
+        hasType[2] = hasType[2] || (info.hash() == entt::type_hash<char>::value());
     });
 
     ASSERT_TRUE(!hasType[0] && hasType[1] && !hasType[2]);