storage_type[_t]: flip entity type and value type
This commit is contained in:
@@ -134,7 +134,7 @@ class basic_group<Entity, owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
|
||||
static constexpr std::size_t index_of = type_list_index_v<std::remove_const_t<Comp>, type_list<std::remove_const_t<Get>...>>;
|
||||
|
||||
template<typename Comp>
|
||||
using storage_for = constness_as_t<storage_type_t<Entity, std::remove_const_t<Comp>>, Comp>;
|
||||
using storage_for = constness_as_t<storage_type_t<std::remove_const_t<Comp>, Entity>, Comp>;
|
||||
|
||||
using basic_common_type = std::common_type_t<typename storage_for<Get>::base_type...>;
|
||||
|
||||
@@ -534,7 +534,7 @@ class basic_group<Entity, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...
|
||||
static constexpr std::size_t index_of = type_list_index_v<std::remove_const_t<Comp>, type_list<std::remove_const_t<Owned>..., std::remove_const_t<Get>...>>;
|
||||
|
||||
template<typename Comp>
|
||||
using storage_for = constness_as_t<storage_type_t<Entity, std::remove_const_t<Comp>>, Comp>;
|
||||
using storage_for = constness_as_t<storage_type_t<std::remove_const_t<Comp>, Entity>, Comp>;
|
||||
|
||||
basic_group(const std::size_t &extent, storage_for<Owned> &...opool, storage_for<Get> &...gpool) noexcept
|
||||
: pools{&opool..., &gpool...},
|
||||
|
||||
@@ -222,7 +222,7 @@ class basic_registry {
|
||||
using basic_common_type = basic_sparse_set<Entity>;
|
||||
|
||||
template<typename Comp>
|
||||
using storage_for = constness_as_t<storage_type_t<Entity, std::remove_const_t<Comp>>, Comp>;
|
||||
using storage_for = constness_as_t<storage_type_t<std::remove_const_t<Comp>, Entity>, Comp>;
|
||||
|
||||
template<typename...>
|
||||
struct group_handler;
|
||||
|
||||
@@ -900,10 +900,10 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Provides a common way to access certain properties of storage types.
|
||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||
* @tparam Type Storage value type.
|
||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||
*/
|
||||
template<typename Entity, typename Type, typename = void>
|
||||
template<typename Type, typename Entity, typename = void>
|
||||
struct storage_type {
|
||||
/*! @brief Resulting type after component-to-storage conversion. */
|
||||
using type = sigh_storage_mixin<basic_storage<Type, Entity>>;
|
||||
@@ -911,11 +911,11 @@ struct storage_type {
|
||||
|
||||
/**
|
||||
* @brief Helper type.
|
||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||
* @tparam Type Storage value type.
|
||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||
*/
|
||||
template<typename Entity, typename Type>
|
||||
using storage_type_t = typename storage_type<Entity, Type>::type;
|
||||
template<typename Type, typename Entity>
|
||||
using storage_type_t = typename storage_type<Type, Entity>::type;
|
||||
|
||||
} // namespace entt
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ class basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>> {
|
||||
friend class basic_view;
|
||||
|
||||
template<typename Comp>
|
||||
using storage_for = constness_as_t<storage_type_t<Entity, std::remove_const_t<Comp>>, Comp>;
|
||||
using storage_for = constness_as_t<storage_type_t<std::remove_const_t<Comp>, Entity>, Comp>;
|
||||
|
||||
[[nodiscard]] auto opaque_check() const noexcept {
|
||||
std::array<const base_type *, sizeof...(Component) - 1u> other{};
|
||||
@@ -544,7 +544,7 @@ class basic_view<Entity, get_t<Component>, exclude_t<>, std::void_t<std::enable_
|
||||
template<typename, typename, typename, typename>
|
||||
friend class basic_view;
|
||||
|
||||
using storage_for = constness_as_t<storage_type_t<Entity, std::remove_const_t<Component>>, Component>;
|
||||
using storage_for = constness_as_t<storage_type_t<std::remove_const_t<Component>, Entity>, Component>;
|
||||
|
||||
public:
|
||||
/*! @brief Underlying entity identifier. */
|
||||
|
||||
@@ -665,10 +665,10 @@ TEST(NonOwningGroup, Storage) {
|
||||
const auto entity = registry.create();
|
||||
const auto group = registry.group(entt::get<int, const char>);
|
||||
|
||||
static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<entt::entity, 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> &>);
|
||||
|
||||
ASSERT_EQ(group.size(), 0u);
|
||||
|
||||
@@ -1445,10 +1445,10 @@ TEST(OwningGroup, Storage) {
|
||||
const auto entity = registry.create();
|
||||
const auto group = registry.group<int>(entt::get<const char>);
|
||||
|
||||
static_assert(std::is_same_v<decltype(group.storage<0u>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const entt::storage_type_t<entt::entity, 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> &>);
|
||||
|
||||
ASSERT_EQ(group.size(), 0u);
|
||||
|
||||
|
||||
@@ -1943,11 +1943,11 @@ TEST(Registry, RuntimePools) {
|
||||
auto &storage = registry.storage<empty_type>("other"_hs);
|
||||
const auto entity = registry.create();
|
||||
|
||||
static_assert(std::is_same_v<decltype(registry.storage<empty_type>()), entt::storage_type_t<entt::entity, empty_type> &>);
|
||||
static_assert(std::is_same_v<decltype(std::as_const(registry).storage<empty_type>()), const entt::storage_type_t<entt::entity, empty_type> &>);
|
||||
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("other"_hs)->second), entt::storage_type_t<entt::entity, empty_type>::base_type &>);
|
||||
static_assert(std::is_same_v<decltype(std::as_const(registry).storage("other"_hs)->second), const entt::storage_type_t<entt::entity, empty_type>::base_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 &>);
|
||||
|
||||
ASSERT_NE(registry.storage("other"_hs), registry.storage().end());
|
||||
ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), registry.storage().end());
|
||||
|
||||
@@ -376,8 +376,8 @@ TEST(SingleComponentView, FrontBack) {
|
||||
|
||||
TEST(SingleComponentView, DeductionGuide) {
|
||||
entt::registry registry;
|
||||
entt::storage_type_t<entt::entity, int> istorage;
|
||||
entt::storage_type_t<entt::entity, stable_type> sstorage;
|
||||
entt::storage_type_t<int, entt::entity> istorage;
|
||||
entt::storage_type_t<stable_type, entt::entity> 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<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 cview = registry.view<const char>();
|
||||
|
||||
static_assert(std::is_same_v<decltype(view.storage()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage()), const entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<0u>()), const entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<const char>()), const entt::storage_type_t<entt::entity, 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> &>);
|
||||
|
||||
ASSERT_EQ(view.size(), 0u);
|
||||
ASSERT_EQ(cview.size(), 0u);
|
||||
@@ -1031,9 +1031,9 @@ TEST(MultiComponentView, ExtendedGet) {
|
||||
|
||||
TEST(MultiComponentView, DeductionGuide) {
|
||||
entt::registry registry;
|
||||
entt::storage_type_t<entt::entity, int> istorage;
|
||||
entt::storage_type_t<entt::entity, double> dstorage;
|
||||
entt::storage_type_t<entt::entity, stable_type> sstorage;
|
||||
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;
|
||||
|
||||
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})>);
|
||||
@@ -1159,8 +1159,8 @@ TEST(MultiComponentView, StableTypeWithExcludedComponent) {
|
||||
|
||||
TEST(MultiComponentView, SameComponentTypes) {
|
||||
entt::registry registry;
|
||||
entt::storage_type_t<entt::entity, int> storage;
|
||||
entt::storage_type_t<entt::entity, int> other;
|
||||
entt::storage_type_t<int, entt::entity> storage;
|
||||
entt::storage_type_t<int, entt::entity> other;
|
||||
entt::basic_view view{storage, other};
|
||||
|
||||
storage.bind(entt::forward_as_any(registry));
|
||||
@@ -1240,10 +1240,10 @@ TEST(MultiComponentView, Storage) {
|
||||
const auto entity = registry.create();
|
||||
const auto view = registry.view<int, const char>();
|
||||
|
||||
static_assert(std::is_same_v<decltype(view.storage<0u>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<1u>()), const entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<const char>()), const entt::storage_type_t<entt::entity, 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> &>);
|
||||
|
||||
ASSERT_EQ(view.size_hint(), 0u);
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#include <entt/entity/entity.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
|
||||
template<typename Entity, typename Type>
|
||||
struct entt::storage_type<Entity, Type> {
|
||||
template<typename Type, typename Entity>
|
||||
struct entt::storage_type<Type, Entity> {
|
||||
// no signal regardless of component type ...
|
||||
using type = basic_storage<Type, Entity>;
|
||||
};
|
||||
|
||||
template<typename Entity>
|
||||
struct entt::storage_type<Entity, char> {
|
||||
struct entt::storage_type<char, Entity> {
|
||||
// ... unless it's char, because yes.
|
||||
using type = sigh_storage_mixin<basic_storage<char, Entity>>;
|
||||
};
|
||||
@@ -20,7 +20,7 @@ template<typename, typename, typename = void>
|
||||
struct has_on_construct: std::false_type {};
|
||||
|
||||
template<typename Entity, typename Type>
|
||||
struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Entity, Type>::on_construct)>>: std::true_type {};
|
||||
struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Type, Entity>::on_construct)>>: std::true_type {};
|
||||
|
||||
template<typename Entity, typename Type>
|
||||
inline constexpr auto has_on_construct_v = has_on_construct<Entity, Type>::value;
|
||||
|
||||
Reference in New Issue
Block a user