sparse_set: also support (in theory) fancy pointers

This commit is contained in:
Michele Caini
2022-01-09 15:06:17 +01:00
parent 1345c257c3
commit c6d3714e6f

View File

@@ -180,7 +180,7 @@ class basic_sparse_set {
using sparse_container_type = std::vector<typename alloc_traits::pointer, typename alloc_traits::template rebind_alloc<typename alloc_traits::pointer>>;
using packed_container_type = std::vector<Entity, alloc>;
[[nodiscard]] auto *sparse_ptr(const Entity entt) const {
[[nodiscard]] auto sparse_ptr(const Entity entt) const {
const auto pos = static_cast<size_type>(entity_traits::to_entity(entt));
const auto page = pos / entity_traits::page_size;
return (page < sparse.size() && sparse[page]) ? (sparse[page] + fast_mod(pos, entity_traits::page_size)) : nullptr;
@@ -580,7 +580,7 @@ public:
* @return True if the sparse set contains the entity, false otherwise.
*/
[[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
const auto *elem = sparse_ptr(entt);
const auto elem = sparse_ptr(entt);
constexpr auto cap = entity_traits::to_entity(null);
// testing versions permits to avoid accessing the packed array
return elem && (((~cap & entity_traits::to_integral(entt)) ^ entity_traits::to_integral(*elem)) < cap);
@@ -593,7 +593,7 @@ public:
* version otherwise.
*/
[[nodiscard]] version_type current(const entity_type entt) const {
const auto *elem = sparse_ptr(entt);
const auto elem = sparse_ptr(entt);
constexpr auto fallback = entity_traits::to_version(tombstone);
return elem ? entity_traits::to_version(*elem) : fallback;
}