group: deprecated ::less, ::each returns only non-empty types now

This commit is contained in:
Michele Caini
2020-03-15 23:50:02 +01:00
parent 97e0d63102
commit 2fcb055c43
3 changed files with 19 additions and 22 deletions
+1
View File
@@ -20,6 +20,7 @@
Next:
* replace observer class with observer functions
* get(cmp, entity) -> void *, set(cmp, entity, void *)
* ENTT_ENABLE_ETO -> ENTT_IS_EMPTY (ignore default constructible)
* WIP:
- deprecate snapshot, loader, ...
+9 -7
View File
@@ -335,7 +335,8 @@ public:
*/
template<typename Func>
void each(Func func) const {
traverse(std::move(func), type_list<Get...>{});
using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
traverse(std::move(func), get_type_list{});
}
/**
@@ -359,9 +360,9 @@ public:
* @param func A valid function object.
*/
template<typename Func>
[[deprecated("use ::each instead")]]
void less(Func func) const {
using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
traverse(std::move(func), get_type_list{});
each(std::move(func));
}
/**
@@ -771,7 +772,9 @@ public:
*/
template<typename Func>
void each(Func func) const {
traverse(std::move(func), type_list<Owned...>{}, type_list<Get...>{});
using owned_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Owned), type_list<>, type_list<Owned>>...>;
using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
traverse(std::move(func), owned_type_list{}, get_type_list{});
}
/**
@@ -795,10 +798,9 @@ public:
* @param func A valid function object.
*/
template<typename Func>
[[deprecated("use ::each instead")]]
void less(Func func) const {
using owned_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Owned), type_list<>, type_list<Owned>>...>;
using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
traverse(std::move(func), owned_type_list{}, get_type_list{});
each(std::move(func));
}
/**
+9 -15
View File
@@ -305,28 +305,25 @@ TEST(NonOwningGroup, IndexRebuiltOnDestroy) {
TEST(NonOwningGroup, ConstNonConstAndAllInBetween) {
entt::registry registry;
auto group = registry.group(entt::get<int, const char, std::true_type>);
auto group = registry.group(entt::get<int, const char>);
ASSERT_EQ(group.size(), decltype(group.size()){0});
const auto entity = registry.create();
registry.assign<int>(entity, 0);
registry.assign<char>(entity, 'c');
registry.assign<std::true_type>(entity);
ASSERT_EQ(group.size(), decltype(group.size()){1});
ASSERT_TRUE((std::is_same_v<decltype(group.get<int>({})), int &>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<const char>({})), const char &>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<std::true_type>({})), std::true_type>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<int, const char, std::true_type>({})), std::tuple<int &, const char &, std::true_type>>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<int, const char>({})), std::tuple<int &, const char &>>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<const char>()), const char *>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<int>()), int *>));
group.each([](auto &&i, auto &&c, auto &&e) {
group.each([](auto &&i, auto &&c) {
ASSERT_TRUE((std::is_same_v<decltype(i), int &>));
ASSERT_TRUE((std::is_same_v<decltype(c), const char &>));
ASSERT_TRUE((std::is_same_v<decltype(e), std::true_type &&>));
});
}
@@ -441,7 +438,7 @@ TEST(NonOwningGroup, EmptyAndNonEmptyTypes) {
ASSERT_TRUE(entity == e0 || entity == e1);
}
group.each([e0, e1](const auto entity, const int &, empty_type) {
group.each([e0, e1](const auto entity, const int &) {
ASSERT_TRUE(entity == e0 || entity == e1);
});
@@ -895,7 +892,7 @@ TEST(OwningGroup, IndexRebuiltOnDestroy) {
TEST(OwningGroup, ConstNonConstAndAllInBetween) {
entt::registry registry;
auto group = registry.group<int, const char>(entt::get<double, const float, std::true_type>);
auto group = registry.group<int, const char>(entt::get<double, const float>);
ASSERT_EQ(group.size(), decltype(group.size()){0});
@@ -904,7 +901,6 @@ TEST(OwningGroup, ConstNonConstAndAllInBetween) {
registry.assign<char>(entity, 'c');
registry.assign<double>(entity, 0.);
registry.assign<float>(entity, 0.f);
registry.assign<std::true_type>(entity);
ASSERT_EQ(group.size(), decltype(group.size()){1});
@@ -912,19 +908,17 @@ TEST(OwningGroup, ConstNonConstAndAllInBetween) {
ASSERT_TRUE((std::is_same_v<decltype(group.get<const char>({})), const char &>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<double>({})), double &>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<const float>({})), const float &>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<std::true_type>({})), std::true_type>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<int, const char, double, const float, std::true_type>({})), std::tuple<int &, const char &, double &, const float &, std::true_type>>));
ASSERT_TRUE((std::is_same_v<decltype(group.get<int, const char, double, const float>({})), std::tuple<int &, const char &, double &, const float &>>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<const float>()), const float *>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<double>()), double *>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<const char>()), const char *>));
ASSERT_TRUE((std::is_same_v<decltype(group.raw<int>()), int *>));
group.each([](auto &&i, auto &&c, auto &&d, auto &&f, auto &&e) {
group.each([](auto &&i, auto &&c, auto &&d, auto &&f) {
ASSERT_TRUE((std::is_same_v<decltype(i), int &>));
ASSERT_TRUE((std::is_same_v<decltype(c), const char &>));
ASSERT_TRUE((std::is_same_v<decltype(d), double &>));
ASSERT_TRUE((std::is_same_v<decltype(f), const float &>));
ASSERT_TRUE((std::is_same_v<decltype(e), std::true_type &&>));
});
}
@@ -1023,7 +1017,7 @@ TEST(OwningGroup, ExcludedComponents) {
TEST(OwningGroup, EmptyAndNonEmptyTypes) {
entt::registry registry;
const auto group = registry.group<empty_type>(entt::get<int>);
const auto group = registry.group<int>(entt::get<empty_type>);
const auto e0 = registry.create();
registry.assign<empty_type>(e0);
@@ -1039,7 +1033,7 @@ TEST(OwningGroup, EmptyAndNonEmptyTypes) {
ASSERT_TRUE(entity == e0 || entity == e1);
}
group.each([e0, e1](const auto entity, empty_type, const int &) {
group.each([e0, e1](const auto entity, const int &) {
ASSERT_TRUE(entity == e0 || entity == e1);
});