Browse Source

storage: add default entity type to storage_type

Michele Caini 3 years ago
parent
commit
7428cb353c

+ 12 - 9
src/entt/entity/fwd.hpp

@@ -7,16 +7,22 @@
 
 
 namespace entt {
 namespace entt {
 
 
-template<typename Entity, typename = std::allocator<Entity>>
+/*! @brief Default entity identifier. */
+enum class entity : id_type {};
+
+template<typename Entity = entity, typename = std::allocator<Entity>>
 class basic_sparse_set;
 class basic_sparse_set;
 
 
-template<typename Type, typename, typename = std::allocator<Type>, typename = void>
+template<typename Type, typename = entity, typename = std::allocator<Type>, typename = void>
 class basic_storage;
 class basic_storage;
 
 
+template<typename, typename = entity, typename = void>
+struct storage_type;
+
 template<typename Type>
 template<typename Type>
 class sigh_storage_mixin;
 class sigh_storage_mixin;
 
 
-template<typename>
+template<typename = entity>
 class basic_registry;
 class basic_registry;
 
 
 template<typename, typename, typename, typename = void>
 template<typename, typename, typename, typename = void>
@@ -88,21 +94,18 @@ using owned_t = type_list<Type...>;
 template<typename... Type>
 template<typename... Type>
 inline constexpr owned_t<Type...> owned{};
 inline constexpr owned_t<Type...> owned{};
 
 
-/*! @brief Default entity identifier. */
-enum class entity : id_type {};
-
 /*! @brief Alias declaration for the most common use case. */
 /*! @brief Alias declaration for the most common use case. */
-using sparse_set = basic_sparse_set<entity>;
+using sparse_set = basic_sparse_set<>;
 
 
 /**
 /**
  * @brief Alias declaration for the most common use case.
  * @brief Alias declaration for the most common use case.
  * @tparam Type Type of objects assigned to the entities.
  * @tparam Type Type of objects assigned to the entities.
  */
  */
 template<typename Type>
 template<typename Type>
-using storage = basic_storage<Type, entity>;
+using storage = basic_storage<Type>;
 
 
 /*! @brief Alias declaration for the most common use case. */
 /*! @brief Alias declaration for the most common use case. */
-using registry = basic_registry<entity>;
+using registry = basic_registry<>;
 
 
 /*! @brief Alias declaration for the most common use case. */
 /*! @brief Alias declaration for the most common use case. */
 using observer = basic_observer<registry>;
 using observer = basic_observer<registry>;

+ 1 - 1
src/entt/entity/storage.hpp

@@ -903,7 +903,7 @@ public:
  * @tparam Type Storage value type.
  * @tparam Type Storage value type.
  * @tparam Entity A valid entity type (see entt_traits for more details).
  * @tparam Entity A valid entity type (see entt_traits for more details).
  */
  */
-template<typename Type, typename Entity, typename = void>
+template<typename Type, typename Entity, typename>
 struct storage_type {
 struct storage_type {
     /*! @brief Resulting type after component-to-storage conversion. */
     /*! @brief Resulting type after component-to-storage conversion. */
     using type = sigh_storage_mixin<basic_storage<Type, Entity>>;
     using type = sigh_storage_mixin<basic_storage<Type, Entity>>;

+ 8 - 8
test/entt/entity/group.cpp

@@ -665,10 +665,10 @@ TEST(NonOwningGroup, Storage) {
     const auto entity = registry.create();
     const auto entity = registry.create();
     const auto group = registry.group(entt::get<int, const char>);
     const auto group = registry.group(entt::get<int, const char>);
 
 
-    static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<char, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<char, entt::entity> &>);
+    static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<char> &>);
+    static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<char> &>);
 
 
     ASSERT_EQ(group.size(), 0u);
     ASSERT_EQ(group.size(), 0u);
 
 
@@ -1445,10 +1445,10 @@ TEST(OwningGroup, Storage) {
     const auto entity = registry.create();
     const auto entity = registry.create();
     const auto group = registry.group<int>(entt::get<const char>);
     const auto group = registry.group<int>(entt::get<const char>);
 
 
-    static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<char, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<char, entt::entity> &>);
+    static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<char> &>);
+    static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<char> &>);
 
 
     ASSERT_EQ(group.size(), 0u);
     ASSERT_EQ(group.size(), 0u);
 
 

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

@@ -1943,11 +1943,11 @@ TEST(Registry, RuntimePools) {
     auto &storage = registry.storage<empty_type>("other"_hs);
     auto &storage = registry.storage<empty_type>("other"_hs);
     const auto entity = registry.create();
     const auto entity = registry.create();
 
 
-    static_assert(std::is_same_v<decltype(registry.storage<empty_type>()), entt::storage_type_t<empty_type, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(std::as_const(registry).storage<empty_type>()), const entt::storage_type_t<empty_type, entt::entity> &>);
+    static_assert(std::is_same_v<decltype(registry.storage<empty_type>()), entt::storage_type_t<empty_type> &>);
+    static_assert(std::is_same_v<decltype(std::as_const(registry).storage<empty_type>()), const entt::storage_type_t<empty_type> &>);
 
 
-    static_assert(std::is_same_v<decltype(registry.storage("other"_hs)->second), entt::storage_type_t<empty_type, entt::entity>::base_type &>);
-    static_assert(std::is_same_v<decltype(std::as_const(registry).storage("other"_hs)->second), const entt::storage_type_t<empty_type, entt::entity>::base_type &>);
+    static_assert(std::is_same_v<decltype(registry.storage("other"_hs)->second), entt::storage_type_t<empty_type>::base_type &>);
+    static_assert(std::is_same_v<decltype(std::as_const(registry).storage("other"_hs)->second), const entt::storage_type_t<empty_type>::base_type &>);
 
 
     ASSERT_NE(registry.storage("other"_hs), registry.storage().end());
     ASSERT_NE(registry.storage("other"_hs), registry.storage().end());
     ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), registry.storage().end());
     ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), registry.storage().end());

+ 17 - 17
test/entt/entity/view.cpp

@@ -376,8 +376,8 @@ TEST(SingleComponentView, FrontBack) {
 
 
 TEST(SingleComponentView, DeductionGuide) {
 TEST(SingleComponentView, DeductionGuide) {
     entt::registry registry;
     entt::registry registry;
-    entt::storage_type_t<int, entt::entity> istorage;
-    entt::storage_type_t<stable_type, entt::entity> sstorage;
+    entt::storage_type_t<int> istorage;
+    entt::storage_type_t<stable_type> sstorage;
 
 
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<int>, entt::exclude_t<>>, decltype(entt::basic_view{istorage})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<int>, entt::exclude_t<>>, decltype(entt::basic_view{istorage})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<const int>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage)})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<const int>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage)})>);
@@ -448,12 +448,12 @@ TEST(SingleComponentView, Storage) {
     const auto view = registry.view<int>();
     const auto view = registry.view<int>();
     const auto cview = registry.view<const char>();
     const auto cview = registry.view<const char>();
 
 
-    static_assert(std::is_same_v<decltype(view.storage()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(cview.storage()), const entt::storage_type_t<char, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(cview.storage<0u>()), const entt::storage_type_t<char, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(cview.storage<const char>()), const entt::storage_type_t<char, entt::entity> &>);
+    static_assert(std::is_same_v<decltype(view.storage()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(cview.storage()), const entt::storage_type_t<char> &>);
+    static_assert(std::is_same_v<decltype(cview.storage<0u>()), const entt::storage_type_t<char> &>);
+    static_assert(std::is_same_v<decltype(cview.storage<const char>()), const entt::storage_type_t<char> &>);
 
 
     ASSERT_EQ(view.size(), 0u);
     ASSERT_EQ(view.size(), 0u);
     ASSERT_EQ(cview.size(), 0u);
     ASSERT_EQ(cview.size(), 0u);
@@ -1031,9 +1031,9 @@ TEST(MultiComponentView, ExtendedGet) {
 
 
 TEST(MultiComponentView, DeductionGuide) {
 TEST(MultiComponentView, DeductionGuide) {
     entt::registry registry;
     entt::registry registry;
-    entt::storage_type_t<int, entt::entity> istorage;
-    entt::storage_type_t<double, entt::entity> dstorage;
-    entt::storage_type_t<stable_type, entt::entity> sstorage;
+    entt::storage_type_t<int> istorage;
+    entt::storage_type_t<double> dstorage;
+    entt::storage_type_t<stable_type> sstorage;
 
 
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<int, double>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, dstorage})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<int, double>, entt::exclude_t<>>, decltype(entt::basic_view{istorage, dstorage})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<const int, double>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage), dstorage})>);
     static_assert(std::is_same_v<entt::basic_view<entt::entity, entt::get_t<const int, double>, entt::exclude_t<>>, decltype(entt::basic_view{std::as_const(istorage), dstorage})>);
@@ -1159,8 +1159,8 @@ TEST(MultiComponentView, StableTypeWithExcludedComponent) {
 
 
 TEST(MultiComponentView, SameComponentTypes) {
 TEST(MultiComponentView, SameComponentTypes) {
     entt::registry registry;
     entt::registry registry;
-    entt::storage_type_t<int, entt::entity> storage;
-    entt::storage_type_t<int, entt::entity> other;
+    entt::storage_type_t<int> storage;
+    entt::storage_type_t<int> other;
     entt::basic_view view{storage, other};
     entt::basic_view view{storage, other};
 
 
     storage.bind(entt::forward_as_any(registry));
     storage.bind(entt::forward_as_any(registry));
@@ -1240,10 +1240,10 @@ TEST(MultiComponentView, Storage) {
     const auto entity = registry.create();
     const auto entity = registry.create();
     const auto view = registry.view<int, const char>();
     const auto view = registry.view<int, const char>();
 
 
-    static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<int, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(view.storage<1u>()), const entt::storage_type_t<char, entt::entity> &>);
-    static_assert(std::is_same_v<decltype(view.storage<const char>()), const entt::storage_type_t<char, entt::entity> &>);
+    static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<int> &>);
+    static_assert(std::is_same_v<decltype(view.storage<1u>()), const entt::storage_type_t<char> &>);
+    static_assert(std::is_same_v<decltype(view.storage<const char>()), const entt::storage_type_t<char> &>);
 
 
     ASSERT_EQ(view.size_hint(), 0u);
     ASSERT_EQ(view.size_hint(), 0u);
 
 

+ 1 - 1
test/example/signal_less.cpp

@@ -20,7 +20,7 @@ template<typename, typename, typename = void>
 struct has_on_construct: std::false_type {};
 struct has_on_construct: std::false_type {};
 
 
 template<typename Entity, typename Type>
 template<typename Entity, typename Type>
-struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Type, Entity>::on_construct)>>: std::true_type {};
+struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Type>::on_construct)>>: std::true_type {};
 
 
 template<typename Entity, typename Type>
 template<typename Entity, typename Type>
 inline constexpr auto has_on_construct_v = has_on_construct<Entity, Type>::value;
 inline constexpr auto has_on_construct_v = has_on_construct<Entity, Type>::value;