registry: refine storage proxy iterator and guarantee iterator conversions
This commit is contained in:
@@ -42,11 +42,10 @@ class storage_proxy_iterator final {
|
||||
template<typename Other>
|
||||
friend class storage_proxy_iterator;
|
||||
|
||||
using first_type = std::remove_reference_t<decltype(std::declval<It>()->first)>;
|
||||
using second_type = std::remove_reference_t<decltype(std::declval<It>()->second)>;
|
||||
using mapped_type = std::remove_reference_t<decltype(std::declval<It>()->second)>;
|
||||
|
||||
public:
|
||||
using value_type = std::pair<first_type, constness_as_t<typename second_type::element_type, second_type> &>;
|
||||
using value_type = std::pair<id_type, constness_as_t<typename mapped_type::element_type, mapped_type> &>;
|
||||
using pointer = input_iterator_pointer<value_type>;
|
||||
using reference = value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
@@ -1989,7 +1989,7 @@ TEST(Registry, StorageProxy) {
|
||||
|
||||
for(auto [id, pool]: registry.storage()) {
|
||||
static_assert(std::is_same_v<decltype(pool), entt::sparse_set &>);
|
||||
static_assert(std::is_same_v<decltype(id), const entt::id_type>);
|
||||
static_assert(std::is_same_v<decltype(id), entt::id_type>);
|
||||
|
||||
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<decltype(curr.second), const entt::sparse_set &>);
|
||||
static_assert(std::is_same_v<decltype(curr.first), const entt::id_type>);
|
||||
static_assert(std::is_same_v<decltype(curr.first), entt::id_type>);
|
||||
|
||||
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<int>(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<decltype(*it), std::pair<entt::id_type, entt::sparse_set &>>);
|
||||
static_assert(std::is_same_v<decltype(*cit), std::pair<entt::id_type, const entt::sparse_set &>>);
|
||||
|
||||
ASSERT_EQ(it->first, entt::type_id<int>().hash());
|
||||
ASSERT_EQ((*it).second.type(), entt::type_id<int>());
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user