Browse Source

table: refined implementation/cleanup

Michele Caini 1 year ago
parent
commit
1e26f3fd81
1 changed files with 10 additions and 17 deletions
  1. 10 17
      src/entt/entity/table.hpp

+ 10 - 17
src/entt/entity/table.hpp

@@ -18,14 +18,6 @@ namespace entt {
 /*! @cond TURN_OFF_DOXYGEN */
 /*! @cond TURN_OFF_DOXYGEN */
 namespace internal {
 namespace internal {
 
 
-struct basic_common_table {
-    using size_type = std::size_t;
-
-    virtual void reserve(const size_type) = 0;
-    [[nodiscard]] virtual size_type capacity() const noexcept = 0;
-    virtual void shrink_to_fit() = 0;
-};
-
 template<typename... It>
 template<typename... It>
 class table_iterator {
 class table_iterator {
     template<typename...>
     template<typename...>
@@ -157,7 +149,7 @@ template<typename... Lhs, typename... Rhs>
  * @tparam Allocator Type of allocator used to manage memory and elements.
  * @tparam Allocator Type of allocator used to manage memory and elements.
  */
  */
 template<typename... Row, typename Allocator>
 template<typename... Row, typename Allocator>
-class basic_table<type_list<Row...>, Allocator>: internal::basic_common_table {
+class basic_table<type_list<Row...>, Allocator> {
     using alloc_traits = std::allocator_traits<Allocator>;
     using alloc_traits = std::allocator_traits<Allocator>;
     static_assert(sizeof...(Row) != 0u, "Empty tables not allowed");
     static_assert(sizeof...(Row) != 0u, "Empty tables not allowed");
 
 
@@ -165,15 +157,12 @@ class basic_table<type_list<Row...>, Allocator>: internal::basic_common_table {
     using container_for = std::vector<Type, typename alloc_traits::template rebind_alloc<Type>>;
     using container_for = std::vector<Type, typename alloc_traits::template rebind_alloc<Type>>;
 
 
     using container_type = std::tuple<container_for<Row>...>;
     using container_type = std::tuple<container_for<Row>...>;
-    using underlying_type = internal::basic_common_table;
 
 
 public:
 public:
     /*! @brief Allocator type. */
     /*! @brief Allocator type. */
     using allocator_type = Allocator;
     using allocator_type = Allocator;
-    /*! @brief Base type. */
-    using base_type = underlying_type;
     /*! @brief Unsigned integer type. */
     /*! @brief Unsigned integer type. */
-    using size_type = typename base_type::size_type;
+    using size_type = std::size_t;
     /*! @brief Input iterator type. */
     /*! @brief Input iterator type. */
     using iterator = internal::table_iterator<typename container_for<Row>::iterator...>;
     using iterator = internal::table_iterator<typename container_for<Row>::iterator...>;
     /*! @brief Constant input iterator type. */
     /*! @brief Constant input iterator type. */
@@ -248,7 +237,7 @@ public:
      *
      *
      * @param cap Desired capacity.
      * @param cap Desired capacity.
      */
      */
-    void reserve(const size_type cap) override {
+    void reserve(const size_type cap) {
         (std::get<container_for<Row>>(payload.first()).reserve(cap), ...);
         (std::get<container_for<Row>>(payload.first()).reserve(cap), ...);
     }
     }
 
 
@@ -257,12 +246,12 @@ public:
      * space for.
      * space for.
      * @return Capacity of the table.
      * @return Capacity of the table.
      */
      */
-    [[nodiscard]] size_type capacity() const noexcept override {
+    [[nodiscard]] size_type capacity() const noexcept {
         return std::get<0>(payload.first()).capacity();
         return std::get<0>(payload.first()).capacity();
     }
     }
 
 
     /*! @brief Requests the removal of unused capacity. */
     /*! @brief Requests the removal of unused capacity. */
-    void shrink_to_fit() override {
+    void shrink_to_fit() {
         (std::get<container_for<Row>>(payload.first()).shrink_to_fit(), ...);
         (std::get<container_for<Row>>(payload.first()).shrink_to_fit(), ...);
     }
     }
 
 
@@ -369,7 +358,11 @@ public:
      */
      */
     template<typename... Args>
     template<typename... Args>
     std::tuple<Row &...> emplace(Args &&...args) {
     std::tuple<Row &...> emplace(Args &&...args) {
-        return std::forward_as_tuple(std::get<container_for<Row>>(payload.first()).emplace_back(std::forward<Args>(args))...);
+        if constexpr(sizeof...(Args) == 0u) {
+            return std::forward_as_tuple(std::get<container_for<Row>>(payload.first()).emplace_back()...);
+        } else {
+            return std::forward_as_tuple(std::get<container_for<Row>>(payload.first()).emplace_back(std::forward<Args>(args))...);
+        }
     }
     }
 
 
     /**
     /**