From 95c142ad655e3bc4c5d404233ebc827013d32c57 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 10 Feb 2025 11:09:43 +0100 Subject: [PATCH] entity: handle conversion warnings --- src/entt/entity/group.hpp | 12 ++++++++---- src/entt/entity/registry.hpp | 2 +- src/entt/entity/sparse_set.hpp | 14 ++++++++------ src/entt/entity/storage.hpp | 14 ++++++++++---- src/entt/entity/view.hpp | 20 ++++++++++++++------ 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 7fc0cbca5..53e7efa4f 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -297,6 +297,8 @@ class basic_group, get_t, exclude_t> { using entity_type = underlying_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Common type among all storage types. */ using common_type = base_type; /*! @brief Random access iterator type. */ @@ -465,7 +467,7 @@ class basic_group, get_t, exclude_t> { * @return The identifier that occupies the given position. */ [[nodiscard]] entity_type operator[](const size_type pos) const { - return begin()[static_cast(pos)]; + return begin()[static_cast(pos)]; } /** @@ -711,6 +713,8 @@ class basic_group, get_t, exclude_t> { using entity_type = underlying_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Common type among all storage types. */ using common_type = base_type; /*! @brief Random access iterator type. */ @@ -794,7 +798,7 @@ class basic_group, get_t, exclude_t> { * @return An iterator to the first entity of the group. */ [[nodiscard]] iterator begin() const noexcept { - return *this ? (handle().end() - static_cast(descriptor->length())) : iterator{}; + return *this ? (handle().end() - static_cast(descriptor->length())) : iterator{}; } /** @@ -824,7 +828,7 @@ class basic_group, get_t, exclude_t> { * reversed group. */ [[nodiscard]] reverse_iterator rend() const noexcept { - return *this ? (handle().rbegin() + static_cast(descriptor->length())) : reverse_iterator{}; + return *this ? (handle().rbegin() + static_cast(descriptor->length())) : reverse_iterator{}; } /** @@ -864,7 +868,7 @@ class basic_group, get_t, exclude_t> { * @return The identifier that occupies the given position. */ [[nodiscard]] entity_type operator[](const size_type pos) const { - return begin()[static_cast(pos)]; + return begin()[static_cast(pos)]; } /** diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 2eb798048..410ee356d 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -576,7 +576,7 @@ class basic_registry { template void destroy(It first, It last) { const auto to = entities.sort_as(first, last); - const auto from = entities.cend() - entities.free_list(); + const auto from = entities.cend() - static_cast(entities.free_list()); for(auto &&curr: pools) { curr.second->remove(from, to); diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 7722d9229..c0572fbca 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -190,7 +190,7 @@ class basic_sparse_set { } [[nodiscard]] auto to_iterator(const Entity entt) const { - return --(end() - static_cast(index(entt))); + return --(end() - static_cast(index(entt))); } [[nodiscard]] auto &assure_at_least(const Entity entt) { @@ -375,7 +375,7 @@ class basic_sparse_set { break; } - return --(end() - static_cast(pos)); + return --(end() - static_cast(pos)); } /*! @brief Forwards variables to derived classes, if any. */ @@ -391,6 +391,8 @@ class basic_sparse_set { using version_type = typename traits_type::version_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Pointer type to contained entities. */ using pointer = typename packed_container_type::const_pointer; /*! @brief Random access iterator type. */ @@ -646,7 +648,7 @@ class basic_sparse_set { * @return An iterator to the first entity of the sparse set. */ [[nodiscard]] iterator begin() const noexcept { - const auto pos = static_cast(packed.size()); + const auto pos = static_cast(packed.size()); return iterator{packed, pos}; } @@ -937,7 +939,7 @@ class basic_sparse_set { } } - packed.erase(packed.begin() + static_cast(from), packed.end()); + packed.erase(packed.begin() + static_cast(from), packed.end()); } } @@ -998,7 +1000,7 @@ class basic_sparse_set { ENTT_ASSERT((mode != deletion_policy::in_place) || (head == max_size), "Sorting with tombstones not allowed"); ENTT_ASSERT(!(length > packed.size()), "Length exceeds the number of elements"); - algo(packed.rend() - static_cast(length), packed.rend(), std::move(compare), std::forward(args)...); + algo(packed.rend() - static_cast(length), packed.rend(), std::move(compare), std::forward(args)...); for(size_type pos{}; pos < length; ++pos) { auto curr = pos; @@ -1051,7 +1053,7 @@ class basic_sparse_set { iterator sort_as(It first, It last) { ENTT_ASSERT((mode != deletion_policy::in_place) || (head == max_size), "Sorting with tombstones not allowed"); const size_type len = (mode == deletion_policy::swap_only) ? head : packed.size(); - auto it = end() - static_cast(len); + auto it = end() - static_cast(len); for(const auto other = end(); (it != other) && (first != last); ++first) { if(const auto curr = *first; contains(curr)) { diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 1dc737608..bc16f4778 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -407,6 +407,8 @@ class basic_storage: public basic_sparse_set(base_type::size()); + const auto pos = static_cast(base_type::size()); return const_iterator{&payload, pos}; } @@ -571,7 +573,7 @@ class basic_storage: public basic_sparse_set(base_type::size()); + const auto pos = static_cast(base_type::size()); return iterator{&payload, pos}; } @@ -808,6 +810,8 @@ class basic_storage>; /*! @brief Constant extended iterable storage proxy. */ @@ -1034,6 +1038,8 @@ class basic_storage using entity_type = Entity; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Extended iterable storage proxy. */ using iterable = iterable_adaptor>; /*! @brief Constant extended iterable storage proxy. */ @@ -1228,7 +1234,7 @@ class basic_storage /*! @copydoc each */ [[nodiscard]] const_iterable each() const noexcept { const auto it = base_type::cend(); - const auto offset = static_cast(base_type::free_list()); + const auto offset = static_cast(base_type::free_list()); return const_iterable{it - offset, it}; } @@ -1246,7 +1252,7 @@ class basic_storage /*! @copydoc reach */ [[nodiscard]] const_reverse_iterable reach() const noexcept { const auto it = base_type::crbegin(); - const auto offset = static_cast(base_type::free_list()); + const auto offset = static_cast(base_type::free_list()); return const_reverse_iterable{it, it + offset}; } diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index c72c86e01..b18a79b28 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -302,6 +302,8 @@ class basic_common_view { using entity_type = typename Type::entity_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Forward iterator type. */ using iterator = internal::view_iterator; @@ -339,7 +341,7 @@ class basic_common_view { * @return An iterator to the first entity of the view. */ [[nodiscard]] iterator begin() const noexcept { - return (index != Get) ? iterator{pools[index]->end() - static_cast(offset()), pools, filter, index} : iterator{}; + return (index != Get) ? iterator{pools[index]->end() - static_cast(offset()), pools, filter, index} : iterator{}; } /** @@ -368,7 +370,7 @@ class basic_common_view { [[nodiscard]] entity_type back() const noexcept { if(index != Get) { auto it = pools[index]->rbegin(); - const auto last = it + static_cast(offset()); + const auto last = it + static_cast(offset()); for(; it != last && !(internal::all_of(pools.begin(), pools.begin() + index, *it) && internal::all_of(pools.begin() + index + 1, pools.end(), *it) && internal::none_of(filter.begin(), filter.end(), *it)); ++it) {} return it == last ? null : *it; } @@ -477,6 +479,8 @@ class basic_view, exclude_t, std::enable_if_t<(sizeof. using entity_type = typename base_type::entity_type; /*! @brief Unsigned integer type. */ using size_type = typename base_type::size_type; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Forward iterator type. */ using iterator = typename base_type::iterator; /*! @brief Iterable view type. */ @@ -695,6 +699,8 @@ class basic_storage_view { using entity_type = typename common_type::entity_type; /*! @brief Unsigned integer type. */ using size_type = std::size_t; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Random access iterator type. */ using iterator = std::conditional_t, typename common_type::iterator>; /*! @brief Reverse iterator type. */ @@ -759,7 +765,7 @@ class basic_storage_view { if constexpr(Policy == deletion_policy::swap_and_pop) { return leading ? leading->begin() : iterator{}; } else if constexpr(Policy == deletion_policy::swap_only) { - return leading ? (leading->end() - leading->free_list()) : iterator{}; + return leading ? (leading->end() - static_cast(leading->free_list())) : iterator{}; } else { static_assert(Policy == deletion_policy::in_place, "Unexpected storage policy"); return leading ? iterator{leading->begin(), {leading}, {}, 0u} : iterator{}; @@ -805,7 +811,7 @@ class basic_storage_view { return leading ? leading->rend() : reverse_iterator{}; } else { static_assert(Policy == deletion_policy::swap_only, "Unexpected storage policy"); - return leading ? (leading->rbegin() + leading->free_list()) : reverse_iterator{}; + return leading ? (leading->rbegin() + static_cast(leading->free_list())) : reverse_iterator{}; } } @@ -818,7 +824,7 @@ class basic_storage_view { if constexpr(Policy == deletion_policy::swap_and_pop) { return empty() ? null : *leading->begin(); } else if constexpr(Policy == deletion_policy::swap_only) { - return empty() ? null : *(leading->end() - leading->free_list()); + return empty() ? null : *(leading->end() - static_cast(leading->free_list())); } else { static_assert(Policy == deletion_policy::in_place, "Unexpected storage policy"); const auto it = begin(); @@ -913,6 +919,8 @@ class basic_view, exclude_t<>> using entity_type = typename base_type::entity_type; /*! @brief Unsigned integer type. */ using size_type = typename base_type::size_type; + /*! @brief Signed integer type. */ + using difference_type = std::ptrdiff_t; /*! @brief Random access iterator type. */ using iterator = typename base_type::iterator; /*! @brief Reverse iterator type. */ @@ -1051,7 +1059,7 @@ class basic_view, exclude_t<>> func(); } } else { - if(const auto len = base_type::size(); len != 0u) { + if(const auto len = static_cast(base_type::size()); len != 0) { for(auto last = storage()->end(), first = last - len; first != last; ++first) { func(*first); }