diff --git a/TODO b/TODO index da5c7b968..98656d7c9 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,6 @@ - ... WIP: -* document the handle way for extended operations * make view pack work also with groups, add multi-type iterator (not only input iterators) * add exclude-only views to combine with packs * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index cd466c209..00601be24 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -418,7 +418,7 @@ public: template void each(Func func) const { for(const auto entt: *handler) { - if constexpr(is_applicable_v) { + if constexpr(is_applicable_v{}, std::declval().get({})))>) { std::apply(func, std::tuple_cat(std::make_tuple(entt), get(entt))); } else { std::apply(func, get(entt)); @@ -912,19 +912,11 @@ public: ENTT_ASSERT(contains(entt)); if constexpr(sizeof...(Component) == 0) { - auto filter = [entt, index = std::get<0>(pools)->index(entt)]([[maybe_unused]] auto *cpool) { - if constexpr(std::is_same_v::storage_category, empty_storage_tag>) { - return std::make_tuple(); - } else { - return std::forward_as_tuple(cpool->raw()[index]); - } - }; - - return std::tuple_cat(filter(std::get *>(pools))..., get_as_tuple(*std::get *>(pools), entt)...); + return std::tuple_cat(get_as_tuple(*std::get *>(pools), entt)..., get_as_tuple(*std::get *>(pools), entt)...); } else if constexpr(sizeof...(Component) == 1) { return (std::get *>(pools)->get(entt), ...); } else { - return std::forward_as_tuple(get(entt)...); + return std::tuple_cat(get_as_tuple(*std::get *>(pools), entt)...); } } @@ -952,21 +944,11 @@ public: */ template void each(Func func) const { - auto owned = std::tuple_cat([length = *length](auto *cpool) { - if constexpr(std::is_same_v::storage_category, empty_storage_tag>) { - return std::make_tuple(); - } else { - return std::make_tuple(cpool->end() - length); - } - }(std::get *>(pools))...); - - for(const auto entt: *this) { - auto args = std::tuple_cat(std::apply([](auto &&... curr) { return std::forward_as_tuple(*curr++...); }, owned), get_as_tuple(*std::get *>(pools), entt)...); - - if constexpr(is_applicable_v) { - std::apply(func, std::tuple_cat(std::make_tuple(entt), args)); - } else { + for(auto args: each()) { + if constexpr(is_applicable_v{}, std::declval().get({})))>) { std::apply(func, args); + } else { + std::apply([&func](auto, auto &&... less) { func(std::forward(less)...); }, args); } } } diff --git a/src/entt/entity/snapshot.hpp b/src/entt/entity/snapshot.hpp index 72fb3aa15..258478b82 100644 --- a/src/entt/entity/snapshot.hpp +++ b/src/entt/entity/snapshot.hpp @@ -36,7 +36,7 @@ class basic_snapshot { template void get(Archive &archive, std::size_t sz, It first, It last) const { - const auto view = reg->view>(); + const auto view = reg->template view>(); archive(typename traits_type::entity_type(sz)); while(first != last) { @@ -167,7 +167,7 @@ class basic_snapshot_loader { entity_type entt{}; - if constexpr(std::tuple_size_vview().get({}))> == 0) { + if constexpr(std::tuple_size_vtemplate view().get({}))> == 0) { while(length--) { archive(entt); const auto entity = reg->valid(entt) ? entt : reg->create(entt); @@ -386,7 +386,7 @@ class basic_continuous_loader { entity_type entt{}; - if constexpr(std::tuple_size_vview().get({}))> == 0) { + if constexpr(std::tuple_size_vtemplate view().get({}))> == 0) { while(length--) { archive(entt); restore(entt); diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index a39dcd175..72380296b 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -478,7 +478,7 @@ public: */ template void sort(Compare compare, Sort algo = Sort{}, Args &&... args) { - sort_n(size(), std::move(compare), std::move(algo), std::forward(args)...); + sort_n(this->size(), std::move(compare), std::move(algo), std::forward(args)...); } private: diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index add0d48cc..fbf0cfb2e 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -237,7 +237,7 @@ class basic_view, Component...> final { [[nodiscard]] unchecked_type unchecked(const basic_sparse_set *cpool) const { std::size_t pos{}; unchecked_type other{}; - ((std::get *>(pools) == cpool ? nullptr : (other[pos] = std::get *>(pools), other[pos++])), ...); + (static_cast(std::get *>(pools) == cpool ? nullptr : (other[pos] = std::get *>(pools), other[pos++])), ...); return other; } @@ -257,7 +257,7 @@ class basic_view, Component...> final { if(((std::is_same_v || std::get *>(pools)->contains(entt)) && ...) && !(std::get *>(filter)->contains(entt) || ...)) { - if constexpr(is_applicable_v) { + if constexpr(is_applicable_v{}, std::declval().get({})))>) { std::apply(func, std::tuple_cat(std::make_tuple(entt), get(entt))); } else { std::apply(func, get(entt)); @@ -271,7 +271,7 @@ class basic_view, Component...> final { if(((std::is_same_v || std::get *>(pools)->contains(entt)) && ...) && !(std::get *>(filter)->contains(entt) || ...)) { - if constexpr(is_applicable_v) { + if constexpr(is_applicable_v{}, std::declval().get({})))>) { std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get(it, entt)...)); } else { std::apply(func, std::tuple_cat(dispatch_get(it, entt)...)); diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index ff5fc958e..4b1f0ffb1 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -350,7 +350,7 @@ TEST(Storage, Raw) { TEST(Storage, SortOrdered) { entt::storage pool; entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}}; - boxed_int values[5u]{12, 9, 6, 3, 1}; + boxed_int values[5u]{{12}, {9}, {6}, {3}, {1}}; pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values)); pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; }); @@ -362,7 +362,7 @@ TEST(Storage, SortOrdered) { TEST(Storage, SortReverse) { entt::storage pool; entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}}; - boxed_int values[5u]{1, 3, 6, 9, 12}; + boxed_int values[5u]{{1}, {3}, {6}, {9}, {12}}; pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values)); pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; }); @@ -374,7 +374,7 @@ TEST(Storage, SortReverse) { TEST(Storage, SortUnordered) { entt::storage pool; entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}}; - boxed_int values[5u]{6, 3, 1, 9, 12}; + boxed_int values[5u]{{6}, {3}, {1}, {9}, {12}}; pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values)); pool.sort([](auto lhs, auto rhs) { return lhs.value < rhs.value; }); @@ -399,7 +399,7 @@ TEST(Storage, SortUnordered) { TEST(Storage, SortRange) { entt::storage pool; entt::entity entities[5u]{entt::entity{12}, entt::entity{42}, entt::entity{7}, entt::entity{3}, entt::entity{9}}; - boxed_int values[5u]{3, 6, 1, 9, 12}; + boxed_int values[5u]{{3}, {6}, {1}, {9}, {12}}; pool.insert(std::begin(entities), std::end(entities), std::begin(values), std::end(values)); pool.sort_n(0u, [](auto lhs, auto rhs) { return lhs.value < rhs.value; });