diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index fbe4b20cc..b4704bcde 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -1025,7 +1025,7 @@ public: */ template void sort(Compare compare, Sort algo = Sort{}, Args &&...args) { - sort_n(static_cast(end() - begin(0)), std::move(compare), std::move(algo), std::forward(args)...); + sort_n((mode == deletion_policy::swap_only) ? head : packed.size(), std::move(compare), std::move(algo), std::forward(args)...); } /** @@ -1044,7 +1044,7 @@ public: template iterator sort_as(It first, It last) { ENTT_ASSERT((mode != deletion_policy::in_place) || (head == max_size), "Sorting with tombstones not allowed"); - auto it = begin(0); + auto it = (mode == deletion_policy::swap_only) ? (end() - static_cast(head)) : begin(); for(const auto other = end(); (it != other) && (first != last); ++first) { if(const auto curr = *first; contains(curr)) {