storage: deprecate ::pack, use ::sort_as instead

This commit is contained in:
Michele Caini
2023-10-20 12:23:43 +02:00
parent c24adea40f
commit aad20ed035
3 changed files with 7 additions and 13 deletions

View File

@@ -1059,7 +1059,7 @@ public:
void sort_as(It first, It last) {
ENTT_ASSERT((mode != deletion_policy::in_place) || (head == traits_type::to_entity(null)), "Sorting with tombstones not allowed");
for(auto it = begin(); it.index() && first != last; ++first) {
for(auto it = begin(0); it.index() && first != last; ++first) {
if(const auto curr = *first; contains(curr)) {
if(const auto entt = *it; entt != curr) {
// basic no-leak guarantee (with invalid state) if swapping throws

View File

@@ -1139,16 +1139,9 @@ public:
* @return The number of elements within the newly created range.
*/
template<typename It>
size_type pack(It first, It last) {
size_type len = base_type::free_list();
for(; first != last; ++first, --len) {
const auto pos = base_type::index(*first);
ENTT_ASSERT(pos < base_type::free_list(), "Invalid element");
base_type::swap_elements(base_type::data()[pos], base_type::data()[static_cast<size_type>(len - 1u)]);
}
return (base_type::free_list() - len);
[[deprecated("use sort_as instead")]] size_type pack(It first, It last) {
base_type::sort_as(first, last);
return static_cast<size_type>(std::distance(first, last));
}
/**

View File

@@ -2013,11 +2013,12 @@ ENTT_DEBUG_TYPED_TEST(SparseSetDeathTest, SortAs) {
ASSERT_DEATH(lhs.sort_as(rhs);, "");
} break;
case entt::deletion_policy::swap_only: {
entity_type entity[2u]{entity_type{3}, entity_type{42}};
entity_type entity[3u]{entity_type{3}, entity_type{42}, entity_type{9}};
lhs.push(std::begin(entity), std::end(entity));
rhs.push(std::rbegin(entity), std::rend(entity));
lhs.erase(entity[1u]);
lhs.erase(entity[0u]);
lhs.bump(entity[0u]);
ASSERT_DEATH(lhs.sort_as(rhs);, "");
} break;