sparse_set: split swap_at for internal uses

This commit is contained in:
Michele Caini
2023-09-07 10:41:12 +02:00
parent a987609b2a
commit 8731eb91f4

View File

@@ -217,6 +217,16 @@ class basic_sparse_set {
}
}
void swap_at(const std::size_t from, const std::size_t to) {
auto &lhs = packed[from];
auto &rhs = packed[to];
sparse_ref(lhs) = traits_type::combine(static_cast<typename traits_type::entity_type>(to), traits_type::to_integral(lhs));
sparse_ref(rhs) = traits_type::combine(static_cast<typename traits_type::entity_type>(from), traits_type::to_integral(rhs));
std::swap(lhs, rhs);
}
underlying_type policy_to_head() {
return traits_type::entity_mask * (mode != deletion_policy::swap_only);
}
@@ -909,12 +919,7 @@ public:
// basic no-leak guarantee if swapping throws
swap_or_move(from, to);
sparse_ref(packed[from]) = traits_type::combine(static_cast<typename traits_type::entity_type>(to), traits_type::to_integral(lhs));
sparse_ref(packed[to]) = traits_type::combine(static_cast<typename traits_type::entity_type>(from), traits_type::to_integral(rhs));
packed[from] = rhs;
packed[to] = lhs;
swap_at(from, to);
}
/**