storage: add storage_type_t
This commit is contained in:
@@ -909,6 +909,14 @@ struct storage_type {
|
||||
using type = sigh_storage_mixin<basic_storage<Entity, Type>>;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Helper type.
|
||||
* @tparam Entity A valid entity type (see entt_traits for more details).
|
||||
* @tparam Type Storage value type.
|
||||
*/
|
||||
template<typename Entity, typename Type>
|
||||
using storage_type_t = typename storage_type<Entity, Type>::type;
|
||||
|
||||
} // namespace entt
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<0u>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
|
||||
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>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<0u>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<int>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<1u>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(group.storage<const char>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
|
||||
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>()), typename entt::storage_type<entt::entity, empty_type>::type &>);
|
||||
static_assert(std::is_same_v<decltype(std::as_const(registry).storage<empty_type>()), const typename entt::storage_type<entt::entity, empty_type>::type &>);
|
||||
static_assert(std::is_same_v<decltype(registry.storage<empty_type>()), typename entt::storage_type_t<entt::entity, empty_type> &>);
|
||||
static_assert(std::is_same_v<decltype(std::as_const(registry).storage<empty_type>()), const typename entt::storage_type_t<entt::entity, empty_type> &>);
|
||||
|
||||
static_assert(std::is_same_v<decltype(registry.storage("other"_hs)->second), typename entt::storage_type<entt::entity, empty_type>::type::base_type &>);
|
||||
static_assert(std::is_same_v<decltype(std::as_const(registry).storage("other"_hs)->second), const typename entt::storage_type<entt::entity, empty_type>::type::base_type &>);
|
||||
static_assert(std::is_same_v<decltype(registry.storage("other"_hs)->second), typename 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 typename entt::storage_type_t<entt::entity, empty_type>::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;
|
||||
typename entt::storage_type<entt::entity, int>::type istorage;
|
||||
typename entt::storage_type<entt::entity, stable_type>::type sstorage;
|
||||
typename entt::storage_type_t<entt::entity, int> istorage;
|
||||
typename entt::storage_type_t<entt::entity, 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<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()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<0u>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<0u>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<const char>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<0u>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<0u>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(cview.storage<const char>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
|
||||
ASSERT_EQ(view.size(), 0u);
|
||||
ASSERT_EQ(cview.size(), 0u);
|
||||
@@ -1031,9 +1031,9 @@ TEST(MultiComponentView, ExtendedGet) {
|
||||
|
||||
TEST(MultiComponentView, DeductionGuide) {
|
||||
entt::registry registry;
|
||||
typename entt::storage_type<entt::entity, int>::type istorage;
|
||||
typename entt::storage_type<entt::entity, double>::type dstorage;
|
||||
typename entt::storage_type<entt::entity, stable_type>::type sstorage;
|
||||
typename entt::storage_type_t<entt::entity, int> istorage;
|
||||
typename entt::storage_type_t<entt::entity, double> dstorage;
|
||||
typename entt::storage_type_t<entt::entity, 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<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;
|
||||
typename entt::storage_type<entt::entity, int>::type storage;
|
||||
typename entt::storage_type<entt::entity, int>::type other;
|
||||
typename entt::storage_type_t<entt::entity, int> storage;
|
||||
typename entt::storage_type_t<entt::entity, int> 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>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), typename entt::storage_type<entt::entity, int>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<1u>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<const char>()), const typename entt::storage_type<entt::entity, char>::type &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<0u>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<int>()), typename entt::storage_type_t<entt::entity, int> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<1u>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
static_assert(std::is_same_v<decltype(view.storage<const char>()), const typename entt::storage_type_t<entt::entity, char> &>);
|
||||
|
||||
ASSERT_EQ(view.size_hint(), 0u);
|
||||
|
||||
|
||||
@@ -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<Entity, Type>::type::on_construct)>>: std::true_type {};
|
||||
struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Entity, Type>::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