Przeglądaj źródła

entity: handle conversion warnings

Michele Caini 1 rok temu
rodzic
commit
95c142ad65

+ 8 - 4
src/entt/entity/group.hpp

@@ -297,6 +297,8 @@ public:
     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 @@ public:
      * @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)];
     }
 
     /**
@@ -711,6 +713,8 @@ public:
     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 @@ public:
      * @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{};
     }
 
     /**
@@ -824,7 +828,7 @@ public:
      * 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{};
     }
 
     /**
@@ -864,7 +868,7 @@ public:
      * @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)];
     }
 
     /**

+ 1 - 1
src/entt/entity/registry.hpp

@@ -576,7 +576,7 @@ public:
     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);

+ 8 - 6
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<typename const_iterator::difference_type>(index(entt)));
+        return --(end() - static_cast<difference_type>(index(entt)));
     }
 
     [[nodiscard]] auto &assure_at_least(const Entity entt) {
@@ -375,7 +375,7 @@ protected:
             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. */
@@ -391,6 +391,8 @@ public:
     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 @@ public:
      * @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};
     }
 
@@ -937,7 +939,7 @@ public:
                 }
             }
 
-            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());
         }
     }
 
@@ -998,7 +1000,7 @@ public:
         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;
@@ -1051,7 +1053,7 @@ public:
     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)) {

+ 10 - 4
src/entt/entity/storage.hpp

@@ -407,6 +407,8 @@ public:
     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. */
@@ -560,7 +562,7 @@ public:
      * @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};
     }
 
@@ -571,7 +573,7 @@ public:
 
     /*! @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};
     }
 
@@ -808,6 +810,8 @@ public:
     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. */
@@ -1034,6 +1038,8 @@ public:
     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. */
@@ -1228,7 +1234,7 @@ public:
     /*! @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};
     }
 
@@ -1246,7 +1252,7 @@ public:
     /*! @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};
     }
 

+ 14 - 6
src/entt/entity/view.hpp

@@ -302,6 +302,8 @@ public:
     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>;
 
@@ -339,7 +341,7 @@ public:
      * @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{};
     }
 
     /**
@@ -368,7 +370,7 @@ public:
     [[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;
         }
@@ -477,6 +479,8 @@ public:
     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 @@ public:
     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. */
@@ -759,7 +765,7 @@ public:
         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{};
@@ -805,7 +811,7 @@ public:
             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{};
         }
     }
 
@@ -818,7 +824,7 @@ public:
         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();
@@ -913,6 +919,8 @@ public:
     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 @@ public:
                     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);
                     }