Bläddra i källkod

sparse_set: review ::push

Michele Caini 1 år sedan
förälder
incheckning
0128620803
1 ändrade filer med 7 tillägg och 4 borttagningar
  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.
      * @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.
-     * @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>
     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;
     }
 
     /**