Browse Source

table: (c)rbegin/(c)rend functions

Michele Caini 1 year ago
parent
commit
9f7668071d
1 changed files with 40 additions and 0 deletions
  1. 40 0
      src/entt/entity/table.hpp

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

@@ -316,6 +316,46 @@ public:
         return {std::get<container_for<Row>>(payload).end()...};
     }
 
+    /**
+     * @brief Returns a reverse iterator to the beginning.
+     *
+     * If the table is empty, the returned iterator will be equal to `rend()`.
+     *
+     * @return An iterator to the first row of the reversed table.
+     */
+    [[nodiscard]] const_reverse_iterator crbegin() const noexcept {
+        return {std::get<container_for<Row>>(payload).crbegin()...};
+    }
+
+    /*! @copydoc crbegin */
+    [[nodiscard]] const_reverse_iterator rbegin() const noexcept {
+        return crbegin();
+    }
+
+    /*! @copydoc rbegin */
+    [[nodiscard]] reverse_iterator rbegin() noexcept {
+        return {std::get<container_for<Row>>(payload).rbegin()...};
+    }
+
+    /**
+     * @brief Returns a reverse iterator to the end.
+     * @return An iterator to the element following the last row of the reversed
+     * table.
+     */
+    [[nodiscard]] const_reverse_iterator crend() const noexcept {
+        return {std::get<container_for<Row>>(payload).crend()...};
+    }
+
+    /*! @copydoc crend */
+    [[nodiscard]] const_reverse_iterator rend() const noexcept {
+        return crend();
+    }
+
+    /*! @copydoc rend */
+    [[nodiscard]] reverse_iterator rend() noexcept {
+        return {std::get<container_for<Row>>(payload).rend()...};
+    }
+
     /*! @brief Clears a table. */
     void clear() {
         (std::get<container_for<Row>>(payload).clear(), ...);