diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 72f52bf36..d81d99a36 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -7,11 +7,11 @@ #include #include "../config/config.h" #include "../core/type_traits.hpp" -#include "sparse_set.hpp" -#include "storage.hpp" -#include "utility.hpp" #include "entity.hpp" #include "fwd.hpp" +#include "pool.hpp" +#include "sparse_set.hpp" +#include "utility.hpp" namespace entt { @@ -68,17 +68,8 @@ class basic_group, get_t> { /*! @brief A registry is allowed to create groups. */ friend class basic_registry; - // I could have used std::conditional_t ... template - struct pool { using type = storage; }; - - // ... if only MSVC didn't have a bug ... - template - struct pool { using type = const storage>; }; - - // ... that forces me to do the same in a worse way! :( - template - using pool_type = typename pool::type; + using pool_type = pool_t; class group_range { friend class basic_group, get_t>; @@ -579,17 +570,8 @@ class basic_group, get_t, Owned...> { /*! @brief A registry is allowed to create groups. */ friend class basic_registry; - // I could have used std::conditional_t ... template - struct pool { using type = storage; }; - - // ... if only MSVC didn't have a bug ... - template - struct pool { using type = const storage>; }; - - // ... that forces me to do the same in a worse way! :( - template - using pool_type = typename pool::type; + using pool_type = pool_t; template using component_iterator = decltype(std::declval>().begin()); diff --git a/src/entt/entity/pool.hpp b/src/entt/entity/pool.hpp new file mode 100644 index 000000000..c84a901fd --- /dev/null +++ b/src/entt/entity/pool.hpp @@ -0,0 +1,53 @@ +#ifndef ENTT_ENTITY_POOL_HPP +#define ENTT_ENTITY_POOL_HPP + + +#include +#include "storage.hpp" + + +namespace entt { + + +/** + * @brief Applies component-to-pool conversion and defines the resulting type as + * the member typedef type. + * + * Formally: + * + * * If the component type is a non-const one, the member typedef type is the + * declared storage type. + * * If the component type is a const one, the member typedef type is the + * declared storage type, except it has a const-qualifier added. + * + * @tparam Entity A valid entity type (see entt_traits for more details). + * @tparam Type Type of objects assigned to the entities. + */ +template +struct pool { + /*! @brief Resulting type after component-to-pool conversion. */ + using type = storage; +}; + + +/*! @copydoc pool */ +template +struct pool { + /*! @brief Resulting type after component-to-pool conversion. */ + using type = std::add_const_t>::type>; +}; + + +/** + * @brief Alias declaration to use to make component-to-pool conversions. + * @tparam Entity A valid entity type (see entt_traits for more details). + * @tparam Type Type of objects assigned to the entities. + */ +template +using pool_t = typename pool::type; + + +} + + +#endif diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 07b6ef05b..2b36035d7 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -10,11 +10,11 @@ #include #include "../config/config.h" #include "../core/type_traits.hpp" -#include "sparse_set.hpp" -#include "storage.hpp" -#include "utility.hpp" #include "entity.hpp" #include "fwd.hpp" +#include "pool.hpp" +#include "sparse_set.hpp" +#include "utility.hpp" namespace entt { @@ -68,17 +68,8 @@ class basic_view, Component...> { /*! @brief A registry is allowed to create views. */ friend class basic_registry; - // I could have used std::conditional_t ... template - struct pool { using type = storage; }; - - // ... if only MSVC didn't have a bug ... - template - struct pool { using type = const storage>; }; - - // ... that forces me to do the same in a worse way! :( - template - using pool_type = typename pool::type; + using pool_type = pool_t; template using component_iterator = decltype(std::declval>().begin()); @@ -628,7 +619,7 @@ class basic_view, Component> { /*! @brief A registry is allowed to create views. */ friend class basic_registry; - using pool_type = std::conditional_t, const storage>, storage>; + using pool_type = pool_t; class view_range { friend class basic_view, Component>; diff --git a/src/entt/entt.hpp b/src/entt/entt.hpp index c970b23ba..bd736ed5b 100644 --- a/src/entt/entt.hpp +++ b/src/entt/entt.hpp @@ -13,6 +13,7 @@ #include "entity/handle.hpp" #include "entity/helper.hpp" #include "entity/observer.hpp" +#include "entity/pool.hpp" #include "entity/registry.hpp" #include "entity/runtime_view.hpp" #include "entity/snapshot.hpp"