Skip to content

Commit

Permalink
entity: handle conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Feb 10, 2025
1 parent 562d25c commit 95c142a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
12 changes: 8 additions & 4 deletions src/entt/entity/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class basic_group<owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
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. */
Expand Down Expand Up @@ -465,7 +467,7 @@ class basic_group<owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
* @return The identifier that occupies the given position.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const {
return begin()[static_cast<typename iterator::difference_type>(pos)];
return begin()[static_cast<difference_type>(pos)];
}

/**
Expand Down Expand Up @@ -711,6 +713,8 @@ class basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> {
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. */
Expand Down Expand Up @@ -794,7 +798,7 @@ class basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> {
* @return An iterator to the first entity of the group.
*/
[[nodiscard]] iterator begin() const noexcept {
return *this ? (handle().end() - static_cast<typename iterator::difference_type>(descriptor->length())) : iterator{};
return *this ? (handle().end() - static_cast<difference_type>(descriptor->length())) : iterator{};
}

/**
Expand Down Expand Up @@ -824,7 +828,7 @@ class basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> {
* reversed group.
*/
[[nodiscard]] reverse_iterator rend() const noexcept {
return *this ? (handle().rbegin() + static_cast<typename reverse_iterator::difference_type>(descriptor->length())) : reverse_iterator{};
return *this ? (handle().rbegin() + static_cast<difference_type>(descriptor->length())) : reverse_iterator{};
}

/**
Expand Down Expand Up @@ -864,7 +868,7 @@ class basic_group<owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> {
* @return The identifier that occupies the given position.
*/
[[nodiscard]] entity_type operator[](const size_type pos) const {
return begin()[static_cast<typename iterator::difference_type>(pos)];
return begin()[static_cast<difference_type>(pos)];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/entt/entity/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ class basic_registry {
template<typename It>
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<typename common_type::difference_type>(entities.free_list());

for(auto &&curr: pools) {
curr.second->remove(from, to);
Expand Down
14 changes: 8 additions & 6 deletions src/entt/entity/sparse_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class basic_sparse_set {
}

[[nodiscard]] auto to_iterator(const Entity entt) const {
return --(end() - static_cast<typename const_iterator::difference_type>(index(entt)));
return --(end() - static_cast<difference_type>(index(entt)));
}

[[nodiscard]] auto &assure_at_least(const Entity entt) {
Expand Down Expand Up @@ -375,7 +375,7 @@ class basic_sparse_set {
break;
}

return --(end() - static_cast<typename iterator::difference_type>(pos));
return --(end() - static_cast<difference_type>(pos));
}

/*! @brief Forwards variables to derived classes, if any. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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<typename const_iterator::difference_type>(packed.size());
const auto pos = static_cast<difference_type>(packed.size());
return iterator{packed, pos};
}

Expand Down Expand Up @@ -937,7 +939,7 @@ class basic_sparse_set {
}
}

packed.erase(packed.begin() + static_cast<typename packed_container_type::difference_type>(from), packed.end());
packed.erase(packed.begin() + static_cast<difference_type>(from), packed.end());
}
}

Expand Down Expand Up @@ -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<typename packed_container_type::difference_type>(length), packed.rend(), std::move(compare), std::forward<Args>(args)...);
algo(packed.rend() - static_cast<difference_type>(length), packed.rend(), std::move(compare), std::forward<Args>(args)...);

for(size_type pos{}; pos < length; ++pos) {
auto curr = pos;
Expand Down Expand Up @@ -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<typename iterator::difference_type>(len);
auto it = end() - static_cast<difference_type>(len);

for(const auto other = end(); (it != other) && (first != last); ++first) {
if(const auto curr = *first; contains(curr)) {
Expand Down
14 changes: 10 additions & 4 deletions src/entt/entity/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
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 Pointer type to contained elements. */
using pointer = typename container_type::pointer;
/*! @brief Constant pointer type to contained elements. */
Expand Down Expand Up @@ -560,7 +562,7 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
* @return An iterator to the first instance of the internal array.
*/
[[nodiscard]] const_iterator cbegin() const noexcept {
const auto pos = static_cast<typename const_iterator::difference_type>(base_type::size());
const auto pos = static_cast<difference_type>(base_type::size());
return const_iterator{&payload, pos};
}

Expand All @@ -571,7 +573,7 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra

/*! @copydoc begin */
[[nodiscard]] iterator begin() noexcept {
const auto pos = static_cast<typename iterator::difference_type>(base_type::size());
const auto pos = static_cast<difference_type>(base_type::size());
return iterator{&payload, pos};
}

Expand Down Expand Up @@ -808,6 +810,8 @@ class basic_storage<Type, Entity, Allocator, std::enable_if_t<component_traits<T
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<internal::extended_storage_iterator<typename base_type::iterator>>;
/*! @brief Constant extended iterable storage proxy. */
Expand Down Expand Up @@ -1034,6 +1038,8 @@ class basic_storage<Entity, Entity, Allocator>
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<internal::extended_storage_iterator<typename base_type::iterator>>;
/*! @brief Constant extended iterable storage proxy. */
Expand Down Expand Up @@ -1228,7 +1234,7 @@ class basic_storage<Entity, Entity, Allocator>
/*! @copydoc each */
[[nodiscard]] const_iterable each() const noexcept {
const auto it = base_type::cend();
const auto offset = static_cast<typename const_iterable::iterator::difference_type>(base_type::free_list());
const auto offset = static_cast<difference_type>(base_type::free_list());
return const_iterable{it - offset, it};
}

Expand All @@ -1246,7 +1252,7 @@ class basic_storage<Entity, Entity, Allocator>
/*! @copydoc reach */
[[nodiscard]] const_reverse_iterable reach() const noexcept {
const auto it = base_type::crbegin();
const auto offset = static_cast<typename const_reverse_iterable::iterator::difference_type>(base_type::free_list());
const auto offset = static_cast<difference_type>(base_type::free_list());
return const_reverse_iterable{it, it + offset};
}

Expand Down
20 changes: 14 additions & 6 deletions src/entt/entity/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<common_type, Checked, Get, Exclude>;

Expand Down Expand Up @@ -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<typename iterator::difference_type>(offset()), pools, filter, index} : iterator{};
return (index != Get) ? iterator{pools[index]->end() - static_cast<difference_type>(offset()), pools, filter, index} : iterator{};
}

/**
Expand Down Expand Up @@ -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<typename iterator::difference_type>(offset());
const auto last = it + static_cast<difference_type>(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;
}
Expand Down Expand Up @@ -477,6 +479,8 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>, 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. */
Expand Down Expand Up @@ -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<Policy == deletion_policy::in_place, internal::view_iterator<common_type, true, 1u, 0u>, typename common_type::iterator>;
/*! @brief Reverse iterator type. */
Expand Down Expand Up @@ -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<difference_type>(leading->free_list())) : iterator{};
} else {
static_assert(Policy == deletion_policy::in_place, "Unexpected storage policy");
return leading ? iterator{leading->begin(), {leading}, {}, 0u} : iterator{};
Expand Down Expand Up @@ -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<difference_type>(leading->free_list())) : reverse_iterator{};
}
}

Expand All @@ -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<difference_type>(leading->free_list()));
} else {
static_assert(Policy == deletion_policy::in_place, "Unexpected storage policy");
const auto it = begin();
Expand Down Expand Up @@ -913,6 +919,8 @@ class basic_view<get_t<Get>, 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. */
Expand Down Expand Up @@ -1051,7 +1059,7 @@ class basic_view<get_t<Get>, exclude_t<>>
func();
}
} else {
if(const auto len = base_type::size(); len != 0u) {
if(const auto len = static_cast<difference_type>(base_type::size()); len != 0) {
for(auto last = storage()->end(), first = last - len; first != last; ++first) {
func(*first);
}
Expand Down

0 comments on commit 95c142a

Please sign in to comment.