group/view: explicit proxy object

This commit is contained in:
Michele Caini
2020-08-03 17:29:34 +02:00
parent a53f0900bd
commit 24248832d1
5 changed files with 110 additions and 108 deletions

View File

@@ -1207,7 +1207,8 @@ for(auto entity: view) {
}
```
Or rely on the `each` member functions to iterate both entities and components:
Or rely on the `each` and `proxy` member functions to iterate both entities and
components at once:
```cpp
// through a callback
@@ -1216,7 +1217,7 @@ registry.view<position, velocity>().each([](auto entity, auto &pos, auto &vel) {
});
// using an input iterator
for(auto &&[entity, pos, vel]: registry.view<position, velocity>().each()) {
for(auto &&[entity, pos, vel]: registry.view<position, velocity>().proxy()) {
// ...
}
```
@@ -1369,7 +1370,8 @@ for(auto entity: group) {
}
```
Or rely on the `each` member functions to iterate both entities and components:
Or rely on the `each` and `proxy` member functions to iterate both entities and
components at once:
```cpp
// through a callback
@@ -1378,7 +1380,7 @@ registry.group<position>(entt::get<velocity>).each([](auto entity, auto &pos, au
});
// using an input iterator
for(auto &&[entity, pos, vel]: registry.group<position>(entt::get<velocity>).each()) {
for(auto &&[entity, pos, vel]: registry.group<position>(entt::get<velocity>).proxy()) {
// ...
}
```

View File

@@ -71,16 +71,16 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
template<typename Component>
using pool_type = pool_t<Entity, Component>;
class group_range {
class group_proxy {
friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
class range_iterator {
friend class group_range;
class proxy_iterator {
friend class group_proxy;
using it_type = typename sparse_set<Entity>::iterator;
using ref_type = decltype(std::tuple_cat(std::declval<std::conditional_t<ENTT_IS_EMPTY(Get), std::tuple<>, std::tuple<pool_type<Get> *>>>()...));
range_iterator(it_type from, ref_type ref) ENTT_NOEXCEPT
proxy_iterator(it_type from, ref_type ref) ENTT_NOEXCEPT
: it{from},
pools{ref}
{}
@@ -98,12 +98,12 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
));
using iterator_category = std::input_iterator_tag;
range_iterator & operator++() ENTT_NOEXCEPT {
proxy_iterator & operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
range_iterator operator++(int) ENTT_NOEXCEPT {
range_iterator orig = *this;
proxy_iterator operator++(int) ENTT_NOEXCEPT {
proxy_iterator orig = *this;
return ++(*this), orig;
}
@@ -111,11 +111,11 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
return std::apply([entt = *it](auto *... cpool) { return reference{entt, cpool->get(entt)...}; }, pools);
}
[[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator==(const proxy_iterator &other) const ENTT_NOEXCEPT {
return other.it == it;
}
[[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator!=(const proxy_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
@@ -124,16 +124,16 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
ref_type pools{};
};
group_range(const sparse_set<Entity> &ref, std::tuple<pool_type<Get> *...> gpools)
group_proxy(const sparse_set<Entity> &ref, std::tuple<pool_type<Get> *...> gpools)
: handler{&ref},
pools{gpools}
{}
public:
using iterator = range_iterator;
using iterator = proxy_iterator;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return range_iterator{handler->begin(), std::tuple_cat([](auto *cpool) {
return proxy_iterator{handler->begin(), std::tuple_cat([](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
return std::make_tuple();
} else {
@@ -143,7 +143,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> {
}
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return range_iterator{handler->end(), std::tuple_cat([](auto *cpool) {
return proxy_iterator{handler->end(), std::tuple_cat([](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
return std::make_tuple();
} else {
@@ -436,8 +436,8 @@ public:
*
* @return An iterable object to use to _visit_ the group.
*/
[[nodiscard]] auto each() const ENTT_NOEXCEPT {
return group_range{*handler, pools};
[[nodiscard]] auto proxy() const ENTT_NOEXCEPT {
return group_proxy{*handler, pools};
}
/**
@@ -576,17 +576,17 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
template<typename Component>
using component_iterator = decltype(std::declval<pool_type<Component>>().begin());
class group_range {
class group_proxy {
friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...>;
class range_iterator {
friend class group_range;
class proxy_iterator {
friend class group_proxy;
using it_type = typename sparse_set<Entity>::iterator;
using owned_type = decltype(std::tuple_cat(std::declval<std::conditional_t<ENTT_IS_EMPTY(Owned), std::tuple<>, std::tuple<component_iterator<Owned>>>>()...));
using get_type = decltype(std::tuple_cat(std::declval<std::conditional_t<ENTT_IS_EMPTY(Get), std::tuple<>, std::tuple<pool_type<Get> *>>>()...));
range_iterator(it_type from, owned_type oref, get_type gref) ENTT_NOEXCEPT
proxy_iterator(it_type from, owned_type oref, get_type gref) ENTT_NOEXCEPT
: it{from},
owned{oref},
get{gref}
@@ -607,12 +607,12 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
));
using iterator_category = std::input_iterator_tag;
range_iterator & operator++() ENTT_NOEXCEPT {
proxy_iterator & operator++() ENTT_NOEXCEPT {
return ++it, std::apply([](auto &&... curr) { (++curr, ...); }, owned), *this;
}
range_iterator operator++(int) ENTT_NOEXCEPT {
range_iterator orig = *this;
proxy_iterator operator++(int) ENTT_NOEXCEPT {
proxy_iterator orig = *this;
return ++(*this), orig;
}
@@ -624,11 +624,11 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
);
}
[[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator==(const proxy_iterator &other) const ENTT_NOEXCEPT {
return other.it == it;
}
[[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator!=(const proxy_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
@@ -638,16 +638,16 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
get_type get{};
};
group_range(std::tuple<pool_type<Owned> *..., pool_type<Get> *...> cpools, const std::size_t &extent)
group_proxy(std::tuple<pool_type<Owned> *..., pool_type<Get> *...> cpools, const std::size_t &extent)
: pools{cpools},
length{&extent}
{}
public:
using iterator = range_iterator;
using iterator = proxy_iterator;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return range_iterator{
return proxy_iterator{
std::get<0>(pools)->sparse_set<Entity>::end() - *length,
std::tuple_cat([length = *length](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
@@ -667,7 +667,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> {
}
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return range_iterator{
return proxy_iterator{
std::get<0>(pools)->sparse_set<Entity>::end(),
std::tuple_cat([](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
@@ -972,8 +972,8 @@ public:
*
* @return An iterable object to use to _visit_ the group.
*/
[[nodiscard]] auto each() const ENTT_NOEXCEPT {
return group_range{pools, *length};
[[nodiscard]] auto proxy() const ENTT_NOEXCEPT {
return group_proxy{pools, *length};
}
/**

View File

@@ -149,15 +149,15 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
underlying_iterator it;
};
class view_range {
class view_proxy {
friend class basic_view<Entity, exclude_t<Exclude...>, Component...>;
class range_iterator {
friend class view_range;
class proxy_iterator {
friend class view_proxy;
using ref_type = decltype(std::tuple_cat(std::declval<std::conditional_t<ENTT_IS_EMPTY(Component), std::tuple<>, std::tuple<pool_type<Component> *>>>()...));
range_iterator(view_iterator from, ref_type ref) ENTT_NOEXCEPT
proxy_iterator(view_iterator from, ref_type ref) ENTT_NOEXCEPT
: it{from},
pools{ref}
{}
@@ -175,12 +175,12 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
));
using iterator_category = std::input_iterator_tag;
range_iterator & operator++() ENTT_NOEXCEPT {
proxy_iterator & operator++() ENTT_NOEXCEPT {
return ++it, *this;
}
range_iterator operator++(int) ENTT_NOEXCEPT {
range_iterator orig = *this;
proxy_iterator operator++(int) ENTT_NOEXCEPT {
proxy_iterator orig = *this;
return ++(*this), orig;
}
@@ -188,11 +188,11 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
return std::apply([entt = *it](auto *... cpool) { return reference{entt, cpool->get(entt)...}; }, pools);
}
[[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator==(const proxy_iterator &other) const ENTT_NOEXCEPT {
return other.it == it;
}
[[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator!=(const proxy_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
@@ -201,17 +201,17 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
const ref_type pools{};
};
view_range(view_iterator from, view_iterator to, std::tuple<pool_type<Component> *...> ref)
view_proxy(view_iterator from, view_iterator to, std::tuple<pool_type<Component> *...> ref)
: first{from},
last{to},
pools{ref}
{}
public:
using iterator = range_iterator;
using iterator = proxy_iterator;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
return range_iterator{first, std::tuple_cat([](auto *cpool) {
return proxy_iterator{first, std::tuple_cat([](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
return std::make_tuple();
} else {
@@ -221,7 +221,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> {
}
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
return range_iterator{last, std::tuple_cat([](auto *cpool) {
return proxy_iterator{last, std::tuple_cat([](auto *cpool) {
if constexpr(ENTT_IS_EMPTY(typename std::decay_t<decltype(*cpool)>::object_type)) {
return std::make_tuple();
} else {
@@ -584,8 +584,8 @@ public:
*
* @return An iterable object to use to _visit_ the view.
*/
[[nodiscard]] auto each() const ENTT_NOEXCEPT {
return view_range{begin(), end(), pools};
[[nodiscard]] auto proxy() const ENTT_NOEXCEPT {
return view_proxy{begin(), end(), pools};
}
/**
@@ -603,9 +603,9 @@ public:
* @return An iterable object to use to _visit_ the view.
*/
template<typename Comp>
[[nodiscard]] auto each() const ENTT_NOEXCEPT {
[[nodiscard]] auto proxy() const ENTT_NOEXCEPT {
const sparse_set<entity_type> &view = *std::get<pool_type<Comp> *>(pools);
return view_range{iterator{view, unchecked(view), filter, view.begin()}, iterator{view, unchecked(view), filter, view.end()}, pools};
return view_proxy{iterator{view, unchecked(view), filter, view.begin()}, iterator{view, unchecked(view), filter, view.end()}, pools};
}
/**
@@ -690,11 +690,11 @@ class basic_view<Entity, exclude_t<>, Component> {
using pool_type = pool_t<Entity, Component>;
class view_range {
class view_proxy {
friend class basic_view<Entity, exclude_t<>, Component>;
class range_iterator {
friend class view_range;
class proxy_iterator {
friend class view_proxy;
using it_type = std::conditional_t<
ENTT_IS_EMPTY(Component),
@@ -702,7 +702,7 @@ class basic_view<Entity, exclude_t<>, Component> {
std::tuple<typename sparse_set<Entity>::iterator, decltype(std::declval<pool_type>().begin())>
>;
range_iterator(it_type from) ENTT_NOEXCEPT
proxy_iterator(it_type from) ENTT_NOEXCEPT
: it{from}
{}
@@ -713,12 +713,12 @@ class basic_view<Entity, exclude_t<>, Component> {
using reference = std::conditional_t<ENTT_IS_EMPTY(Component), std::tuple<Entity>, std::tuple<Entity, Component &>>;
using iterator_category = std::input_iterator_tag;
range_iterator & operator++() ENTT_NOEXCEPT {
proxy_iterator & operator++() ENTT_NOEXCEPT {
return std::apply([](auto &&... curr) { (++curr, ...); }, it), *this;
}
range_iterator operator++(int) ENTT_NOEXCEPT {
range_iterator orig = *this;
proxy_iterator operator++(int) ENTT_NOEXCEPT {
proxy_iterator orig = *this;
return ++(*this), orig;
}
@@ -726,11 +726,11 @@ class basic_view<Entity, exclude_t<>, Component> {
return std::apply([](auto &&... curr) { return reference{*curr...}; }, it);
}
[[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator==(const proxy_iterator &other) const ENTT_NOEXCEPT {
return std::get<0>(other.it) == std::get<0>(it);
}
[[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
[[nodiscard]] bool operator!=(const proxy_iterator &other) const ENTT_NOEXCEPT {
return !(*this == other);
}
@@ -738,26 +738,26 @@ class basic_view<Entity, exclude_t<>, Component> {
it_type it{};
};
view_range(pool_type &ref)
view_proxy(pool_type &ref)
: pool{&ref}
{}
public:
using iterator = range_iterator;
using iterator = proxy_iterator;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
if constexpr(ENTT_IS_EMPTY(Component)) {
return range_iterator{std::make_tuple(pool->sparse_set<entity_type>::begin())};
return proxy_iterator{std::make_tuple(pool->sparse_set<entity_type>::begin())};
} else {
return range_iterator{std::make_tuple(pool->sparse_set<entity_type>::begin(), pool->begin())};
return proxy_iterator{std::make_tuple(pool->sparse_set<entity_type>::begin(), pool->begin())};
}
}
[[nodiscard]] iterator end() const ENTT_NOEXCEPT {
if constexpr(ENTT_IS_EMPTY(Component)) {
return range_iterator{std::make_tuple(pool->sparse_set<entity_type>::end())};
return proxy_iterator{std::make_tuple(pool->sparse_set<entity_type>::end())};
} else {
return range_iterator{std::make_tuple(pool->sparse_set<entity_type>::end(), pool->end())};
return proxy_iterator{std::make_tuple(pool->sparse_set<entity_type>::end(), pool->end())};
}
}
@@ -997,8 +997,8 @@ public:
*
* @return An iterable object to use to _visit_ the view.
*/
[[nodiscard]] auto each() const ENTT_NOEXCEPT {
return view_range{*pool};
[[nodiscard]] auto proxy() const ENTT_NOEXCEPT {
return view_proxy{*pool};
}
private:

View File

@@ -140,7 +140,7 @@ TEST(NonOwningGroup, Empty) {
ASSERT_TRUE(registry.group(entt::get<double, char, int, float>).empty());
}
TEST(NonOwningGroup, Each) {
TEST(NonOwningGroup, Proxy) {
entt::registry registry;
auto group = registry.group(entt::get<int, char>);
@@ -158,7 +158,7 @@ TEST(NonOwningGroup, Each) {
group.each([&cnt](auto, int &, char &) { ++cnt; });
group.each([&cnt](int &, char &) { ++cnt; });
for(auto &&[entt, iv, cv]: group.each()) {
for(auto &&[entt, iv, cv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -170,7 +170,7 @@ TEST(NonOwningGroup, Each) {
cgroup.each([&cnt](auto, const int &, const char &) { --cnt; });
cgroup.each([&cnt](const int &, const char &) { --cnt; });
for(auto &&[entt, iv, cv]: cgroup.each()) {
for(auto &&[entt, iv, cv]: cgroup.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), const int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -315,7 +315,7 @@ TEST(NonOwningGroup, IndexRebuiltOnDestroy) {
ASSERT_EQ(uivalue, 1u);
});
for(auto curr: group.each()) {
for(auto curr: group.proxy()) {
ASSERT_EQ(std::get<0>(curr), e1);
ASSERT_EQ(std::get<1>(curr), 1);
ASSERT_EQ(std::get<2>(curr), 1u);
@@ -345,7 +345,7 @@ TEST(NonOwningGroup, ConstNonConstAndAllInBetween) {
static_assert(std::is_same_v<decltype(c), const char &>);
});
for(auto &&[entt, iv, cv]: group.each()) {
for(auto &&[entt, iv, cv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -467,7 +467,7 @@ TEST(NonOwningGroup, EmptyAndNonEmptyTypes) {
ASSERT_TRUE(entity == e0 || entity == e1);
});
for(auto &&[entt, iv]: group.each()) {
for(auto &&[entt, iv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
ASSERT_TRUE(entt == e0 || entt == e1);
@@ -506,7 +506,7 @@ TEST(NonOwningGroup, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.group(entt::get<int, char, empty_type>).each()) {
for(auto &&[entt, iv, cv]: registry.group(entt::get<int, char, empty_type>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -518,7 +518,7 @@ TEST(NonOwningGroup, EmptyTypes) {
check = false;
});
for(auto &&[entt, iv, cv]: registry.group(entt::get<int, empty_type, char>).each()) {
for(auto &&[entt, iv, cv]: registry.group(entt::get<int, empty_type, char>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -529,7 +529,7 @@ TEST(NonOwningGroup, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.group(entt::get<empty_type, int, char>).each()) {
for(auto &&[entt, iv, cv]: registry.group(entt::get<empty_type, int, char>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -537,7 +537,7 @@ TEST(NonOwningGroup, EmptyTypes) {
}
registry.group(entt::get<int, char, double>).each([](const auto, int, char, double) { FAIL(); });
for([[maybe_unused]] auto curr: registry.group(entt::get<int, char, double>).each()) { FAIL(); }
for([[maybe_unused]] auto curr: registry.group(entt::get<int, char, double>).proxy()) { FAIL(); }
}
TEST(NonOwningGroup, FrontBack) {
@@ -697,7 +697,7 @@ TEST(OwningGroup, Empty) {
ASSERT_TRUE((registry.group<double, float>(entt::get<char, int>).empty()));
}
TEST(OwningGroup, Each) {
TEST(OwningGroup, Proxy) {
entt::registry registry;
auto group = registry.group<int>(entt::get<char>);
@@ -715,7 +715,7 @@ TEST(OwningGroup, Each) {
group.each([&cnt](auto, int &, char &) { ++cnt; });
group.each([&cnt](int &, char &) { ++cnt; });
for(auto &&[entt, iv, cv]: group.each()) {
for(auto &&[entt, iv, cv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -727,7 +727,7 @@ TEST(OwningGroup, Each) {
cgroup.each([&cnt](auto, const int &, const char &) { --cnt; });
cgroup.each([&cnt](const int &, const char &) { --cnt; });
for(auto &&[entt, iv, cv]: cgroup.each()) {
for(auto &&[entt, iv, cv]: cgroup.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), const int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -956,7 +956,7 @@ TEST(OwningGroup, IndexRebuiltOnDestroy) {
ASSERT_EQ(uivalue, 1u);
});
for(auto curr: group.each()) {
for(auto curr: group.proxy()) {
ASSERT_EQ(std::get<0>(curr), e1);
ASSERT_EQ(std::get<1>(curr), 1);
ASSERT_EQ(std::get<2>(curr), 1u);
@@ -994,7 +994,7 @@ TEST(OwningGroup, ConstNonConstAndAllInBetween) {
static_assert(std::is_same_v<decltype(f), const float &>);
});
for(auto &&[entt, iv, cv, dv, fv]: group.each()) {
for(auto &&[entt, iv, cv, dv, fv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -1118,7 +1118,7 @@ TEST(OwningGroup, EmptyAndNonEmptyTypes) {
ASSERT_TRUE(entity == e0 || entity == e1);
});
for(auto &&[entt, iv]: group.each()) {
for(auto &&[entt, iv]: group.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
ASSERT_TRUE(entt == e0 || entt == e1);
@@ -1157,7 +1157,7 @@ TEST(OwningGroup, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.group<int>(entt::get<char, empty_type>).each()) {
for(auto &&[entt, iv, cv]: registry.group<int>(entt::get<char, empty_type>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -1169,7 +1169,7 @@ TEST(OwningGroup, EmptyTypes) {
check = false;
});
for(auto &&[entt, cv, iv]: registry.group<char>(entt::get<empty_type, int>).each()) {
for(auto &&[entt, cv, iv]: registry.group<char>(entt::get<empty_type, int>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(cv), char &>);
static_assert(std::is_same_v<decltype(iv), int &>);
@@ -1180,7 +1180,7 @@ TEST(OwningGroup, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.group<empty_type>(entt::get<int, char>).each()) {
for(auto &&[entt, iv, cv]: registry.group<empty_type>(entt::get<int, char>).proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -1188,7 +1188,7 @@ TEST(OwningGroup, EmptyTypes) {
}
registry.group<double>(entt::get<int, char>).each([](const auto, double, int, char) { FAIL(); });
for([[maybe_unused]] auto curr: registry.group<double>(entt::get<int, char>).each()) { FAIL(); }
for([[maybe_unused]] auto curr: registry.group<double>(entt::get<int, char>).proxy()) { FAIL(); }
}
TEST(OwningGroup, FrontBack) {

View File

@@ -101,7 +101,7 @@ TEST(SingleComponentView, Empty) {
ASSERT_EQ(view.begin(), view.end());
}
TEST(SingleComponentView, Each) {
TEST(SingleComponentView, Proxy) {
entt::registry registry;
registry.emplace<int>(registry.create());
@@ -114,7 +114,7 @@ TEST(SingleComponentView, Each) {
view.each([&cnt](auto, int &) { ++cnt; });
view.each([&cnt](int &) { ++cnt; });
for(auto &&[entt, iv]: view.each()) {
for(auto &&[entt, iv]: view.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
++cnt;
@@ -125,7 +125,7 @@ TEST(SingleComponentView, Each) {
cview.each([&cnt](auto, const int &) { --cnt; });
cview.each([&cnt](const int &) { --cnt; });
for(auto &&[entt, iv]: cview.each()) {
for(auto &&[entt, iv]: cview.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), const int &>);
--cnt;
@@ -163,12 +163,12 @@ TEST(SingleComponentView, ConstNonConstAndAllInBetween) {
static_assert(std::is_same_v<decltype(i), const int &>);
});
for(auto &&[entt, iv]: view.each()) {
for(auto &&[entt, iv]: view.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
}
for(auto &&[entt, iv]: cview.each()) {
for(auto &&[entt, iv]: cview.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), const int &>);
}
@@ -234,7 +234,7 @@ TEST(SingleComponentView, EmptyTypes) {
check = false;
});
for(auto &&[entt]: registry.view<empty_type>().each()) {
for(auto &&[entt]: registry.view<empty_type>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
ASSERT_EQ(entity, entt);
}
@@ -248,7 +248,7 @@ TEST(SingleComponentView, EmptyTypes) {
check = false;
});
for(auto &&[entt, iv]: registry.view<int>().each()) {
for(auto &&[entt, iv]: registry.view<int>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
ASSERT_EQ(entity, entt);
@@ -391,7 +391,7 @@ TEST(MultiComponentView, Empty) {
ASSERT_EQ(view.begin(), view.end());
}
TEST(MultiComponentView, Each) {
TEST(MultiComponentView, Proxy) {
entt::registry registry;
const auto e0 = registry.create();
@@ -409,7 +409,7 @@ TEST(MultiComponentView, Each) {
view.each([&cnt](auto, int &, char &) { ++cnt; });
view.each([&cnt](int &, char &) { ++cnt; });
for(auto &&[entt, iv, cv]: view.each()) {
for(auto &&[entt, iv, cv]: view.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -421,7 +421,7 @@ TEST(MultiComponentView, Each) {
cview.each([&cnt](auto, const int &, const char &) { --cnt; });
cview.each([&cnt](const int &, const char &) { --cnt; });
for(auto &&[entt, iv, cv]: cview.each()) {
for(auto &&[entt, iv, cv]: cview.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), const int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -462,7 +462,7 @@ TEST(MultiComponentView, EachWithSuggestedType) {
auto value = registry.view<int, char>().size();
for(auto curr: registry.view<int, char>().each()) {
for(auto curr: registry.view<int, char>().proxy()) {
ASSERT_EQ(std::get<1>(curr), --value);
}
@@ -472,7 +472,7 @@ TEST(MultiComponentView, EachWithSuggestedType) {
value = {};
for(auto curr: registry.view<int, char>().each<int>()) {
for(auto curr: registry.view<int, char>().proxy<int>()) {
ASSERT_EQ(std::get<1>(curr), value++);
}
}
@@ -498,7 +498,7 @@ TEST(MultiComponentView, EachWithHoles) {
ASSERT_EQ(i, 0);
});
for(auto curr: view.each()) {
for(auto curr: view.proxy()) {
ASSERT_EQ(std::get<0>(curr), e0);
ASSERT_EQ(std::get<1>(curr), '0');
ASSERT_EQ(std::get<2>(curr), 0);
@@ -528,7 +528,7 @@ TEST(MultiComponentView, ConstNonConstAndAllInBetween) {
static_assert(std::is_same_v<decltype(c), const char &>);
});
for(auto &&[entt, iv, cv]: view.each()) {
for(auto &&[entt, iv, cv]: view.proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), const char &>);
@@ -642,7 +642,7 @@ TEST(MultiComponentView, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.view<int, char, empty_type>().each()) {
for(auto &&[entt, iv, cv]: registry.view<int, char, empty_type>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -654,7 +654,7 @@ TEST(MultiComponentView, EmptyTypes) {
check = false;
});
for(auto &&[entt, iv, cv]: registry.view<int, empty_type, char>().each()) {
for(auto &&[entt, iv, cv]: registry.view<int, empty_type, char>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -665,7 +665,7 @@ TEST(MultiComponentView, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.view<empty_type, int, char>().each()) {
for(auto &&[entt, iv, cv]: registry.view<empty_type, int, char>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -676,7 +676,7 @@ TEST(MultiComponentView, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv]: registry.view<empty_type, int, char>().each<empty_type>()) {
for(auto &&[entt, iv, cv]: registry.view<empty_type, int, char>().proxy<empty_type>()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -688,7 +688,7 @@ TEST(MultiComponentView, EmptyTypes) {
check = false;
});
for(auto &&[entt, iv, cv]: registry.view<int, empty_type, char>().each<empty_type>()) {
for(auto &&[entt, iv, cv]: registry.view<int, empty_type, char>().proxy<empty_type>()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);
@@ -699,7 +699,7 @@ TEST(MultiComponentView, EmptyTypes) {
ASSERT_EQ(entity, entt);
});
for(auto &&[entt, iv, cv, dv]: registry.view<int, char, double>().each()) {
for(auto &&[entt, iv, cv, dv]: registry.view<int, char, double>().proxy()) {
static_assert(std::is_same_v<decltype(entt), entt::entity>);
static_assert(std::is_same_v<decltype(iv), int &>);
static_assert(std::is_same_v<decltype(cv), char &>);