Explorar o código

table: ::erase functions

Michele Caini hai 1 ano
pai
achega
d990d4e928
Modificáronse 1 ficheiros con 20 adicións e 0 borrados
  1. 20 0
      src/entt/entity/table.hpp

+ 20 - 0
src/entt/entity/table.hpp

@@ -8,6 +8,7 @@
 #include <type_traits>
 #include <type_traits>
 #include <utility>
 #include <utility>
 #include <vector>
 #include <vector>
+#include "../config/config.h"
 #include "../core/compressed_pair.hpp"
 #include "../core/compressed_pair.hpp"
 #include "../core/iterator.hpp"
 #include "../core/iterator.hpp"
 #include "fwd.hpp"
 #include "fwd.hpp"
@@ -372,6 +373,25 @@ public:
         return std::forward_as_tuple(std::get<container_for<Row>>(payload.first()).emplace_back(std::forward<Args>(args))...);
         return std::forward_as_tuple(std::get<container_for<Row>>(payload.first()).emplace_back(std::forward<Args>(args))...);
     }
     }
 
 
+    /**
+     * @brief Removes a row from a table.
+     * @param pos An iterator to the row to remove.
+     * @return An iterator following the removed row.
+     */
+    iterator erase(const_iterator pos) {
+        const auto diff = pos - begin();
+        return {std::get<container_for<Row>>(payload.first()).erase(std::get<container_for<Row>>(payload.first()).begin() + diff)...};
+    }
+
+    /**
+     * @brief Removes a row from a table.
+     * @param pos Index of the row to remove.
+     */
+    void erase(const size_type pos) {
+        ENTT_ASSERT(pos < size(), "Index out of bounds");
+        erase(begin() + static_cast<typename const_iterator::difference_type>(pos));
+    }
+
     /**
     /**
      * @brief Returns the row data at specified location.
      * @brief Returns the row data at specified location.
      * @param pos The row for which to return the data.
      * @param pos The row for which to return the data.