Parcourir la source

sparse_set: review ::push

Michele Caini il y a 2 ans
Parent
commit
0128620803
1 fichiers modifiés avec 7 ajouts et 4 suppressions
  1. 7 4
      src/entt/entity/sparse_set.hpp

+ 7 - 4
src/entt/entity/sparse_set.hpp

@@ -804,15 +804,18 @@ public:
      * @tparam It Type of input iterator.
      * @tparam It Type of input iterator.
      * @param first An iterator to the first element of the range of entities.
      * @param first An iterator to the first element of the range of entities.
      * @param last An iterator past the last element of the range of entities.
      * @param last An iterator past the last element of the range of entities.
-     * @return Iterator pointing to the first element inserted, if any.
+     * @return Iterator pointing to the first element inserted in case of
+     * success, the `end()` iterator otherwise.
      */
      */
     template<typename It>
     template<typename It>
     iterator push(It first, It last) {
     iterator push(It first, It last) {
-        for(auto it = first; it != last; ++it) {
-            try_emplace(*it, true);
+        auto curr = end();
+
+        for(; first != last; ++first) {
+            curr = try_emplace(*first, true);
         }
         }
 
 
-        return first == last ? end() : begin(0);
+        return curr;
     }
     }
 
 
     /**
     /**