From 2e6cfc08f0668e9537ee349f2ac9bebfab756089 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 25 Mar 2022 17:20:23 +0100 Subject: [PATCH] registry: refine storage proxy iterator and guarantee iterator conversions --- src/entt/entity/registry.hpp | 5 ++--- test/entt/entity/registry.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index a285397b4..aa3aa3953 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -42,11 +42,10 @@ class storage_proxy_iterator final { template friend class storage_proxy_iterator; - using first_type = std::remove_reference_t()->first)>; - using second_type = std::remove_reference_t()->second)>; + using mapped_type = std::remove_reference_t()->second)>; public: - using value_type = std::pair &>; + using value_type = std::pair &>; using pointer = input_iterator_pointer; using reference = value_type; using difference_type = std::ptrdiff_t; diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index d4009ed33..6fe7dbc21 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1989,7 +1989,7 @@ TEST(Registry, StorageProxy) { for(auto [id, pool]: registry.storage()) { static_assert(std::is_same_v); - static_assert(std::is_same_v); + static_assert(std::is_same_v); ASSERT_TRUE(pool.contains(entity)); ASSERT_EQ(std::addressof(storage), std::addressof(pool)); @@ -1998,7 +1998,7 @@ TEST(Registry, StorageProxy) { for(auto &&curr: std::as_const(registry).storage()) { static_assert(std::is_same_v); - static_assert(std::is_same_v); + static_assert(std::is_same_v); ASSERT_TRUE(curr.second.contains(entity)); ASSERT_EQ(std::addressof(storage), std::addressof(curr.second)); @@ -2061,6 +2061,35 @@ TEST(Registry, StorageProxyIterator) { ASSERT_NE(cit, std::as_const(registry).storage().end()); } +TEST(Registry, StorageProxyIteratorConversion) { + entt::registry registry; + const auto entity = registry.create(); + registry.emplace(entity); + + auto proxy = registry.storage(); + auto cproxy = std::as_const(registry).storage(); + + typename decltype(proxy)::iterator it = proxy.begin(); + typename decltype(cproxy)::iterator cit = it; + + static_assert(std::is_same_v>); + static_assert(std::is_same_v>); + + ASSERT_EQ(it->first, entt::type_id().hash()); + ASSERT_EQ((*it).second.type(), entt::type_id()); + ASSERT_EQ(it->first, cit->first); + ASSERT_EQ((*it).second.type(), (*cit).second.type()); + + ASSERT_EQ(it - cit, 0); + ASSERT_EQ(cit - it, 0); + ASSERT_LE(it, cit); + ASSERT_LE(cit, it); + ASSERT_GE(it, cit); + ASSERT_GE(cit, it); + ASSERT_EQ(it, cit); + ASSERT_NE(++cit, it); +} + TEST(Registry, NoEtoType) { entt::registry registry; const auto entity = registry.create();