1
0
Эх сурвалжийг харах

registry: ::storage<T> const correctness - close #1217

Michele Caini 1 жил өмнө
parent
commit
86c3c4565b

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

@@ -449,7 +449,7 @@ public:
      */
      */
     template<typename Type>
     template<typename Type>
     storage_for_type<Type> &storage(const id_type id = type_hash<Type>::value()) {
     storage_for_type<Type> &storage(const id_type id = type_hash<Type>::value()) {
-        return assure<Type>(id);
+        return assure<std::remove_const_t<Type>>(id);
     }
     }
 
 
     /**
     /**
@@ -460,7 +460,7 @@ public:
      */
      */
     template<typename Type>
     template<typename Type>
     [[nodiscard]] const storage_for_type<Type> *storage(const id_type id = type_hash<Type>::value()) const {
     [[nodiscard]] const storage_for_type<Type> *storage(const id_type id = type_hash<Type>::value()) const {
-        return assure<Type>(id);
+        return assure<std::remove_const_t<Type>>(id);
     }
     }
 
 
     /**
     /**

+ 7 - 3
test/entt/entity/registry.cpp

@@ -484,16 +484,20 @@ TEST(Registry, Storage) {
     const auto entity = registry.create();
     const auto entity = registry.create();
 
 
     testing::StaticAssertTypeEq<decltype(registry.storage<test::empty>()), entt::storage_type_t<test::empty> &>();
     testing::StaticAssertTypeEq<decltype(registry.storage<test::empty>()), entt::storage_type_t<test::empty> &>();
+    testing::StaticAssertTypeEq<decltype(registry.storage<const test::empty>()), const entt::storage_type_t<test::empty> &>();
     testing::StaticAssertTypeEq<decltype(std::as_const(registry).storage<test::empty>()), const entt::storage_type_t<test::empty> *>();
     testing::StaticAssertTypeEq<decltype(std::as_const(registry).storage<test::empty>()), const entt::storage_type_t<test::empty> *>();
+    testing::StaticAssertTypeEq<decltype(std::as_const(registry).storage<const test::empty>()), const entt::storage_type_t<test::empty> *>();
 
 
     testing::StaticAssertTypeEq<decltype(registry.storage("other"_hs)), entt::storage_type_t<test::empty>::base_type *>();
     testing::StaticAssertTypeEq<decltype(registry.storage("other"_hs)), entt::storage_type_t<test::empty>::base_type *>();
     testing::StaticAssertTypeEq<decltype(std::as_const(registry).storage("other"_hs)), const entt::storage_type_t<test::empty>::base_type *>();
     testing::StaticAssertTypeEq<decltype(std::as_const(registry).storage("other"_hs)), const entt::storage_type_t<test::empty>::base_type *>();
 
 
-    ASSERT_NE(registry.storage("other"_hs), nullptr);
-    ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), nullptr);
-
     ASSERT_EQ(&registry.storage<test::empty>("other"_hs), &storage);
     ASSERT_EQ(&registry.storage<test::empty>("other"_hs), &storage);
+    ASSERT_EQ(&registry.storage<const test::empty>("other"_hs), &storage);
     ASSERT_NE(std::as_const(registry).storage<test::empty>(), &storage);
     ASSERT_NE(std::as_const(registry).storage<test::empty>(), &storage);
+    ASSERT_NE(std::as_const(registry).storage<const test::empty>(), &storage);
+
+    ASSERT_NE(registry.storage("other"_hs), nullptr);
+    ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), nullptr);
 
 
     ASSERT_FALSE(registry.any_of<test::empty>(entity));
     ASSERT_FALSE(registry.any_of<test::empty>(entity));
     ASSERT_FALSE(storage.contains(entity));
     ASSERT_FALSE(storage.contains(entity));