From 1e26f3fd815febd40d47d247b0beac33cdc97536 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 2 May 2024 16:31:24 +0200 Subject: [PATCH] table: refined implementation/cleanup --- src/entt/entity/table.hpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/entt/entity/table.hpp b/src/entt/entity/table.hpp index 6d97b552e..b0ae6dc06 100644 --- a/src/entt/entity/table.hpp +++ b/src/entt/entity/table.hpp @@ -18,14 +18,6 @@ namespace entt { /*! @cond TURN_OFF_DOXYGEN */ 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 class table_iterator { template @@ -157,7 +149,7 @@ template * @tparam Allocator Type of allocator used to manage memory and elements. */ template -class basic_table, Allocator>: internal::basic_common_table { +class basic_table, Allocator> { using alloc_traits = std::allocator_traits; static_assert(sizeof...(Row) != 0u, "Empty tables not allowed"); @@ -165,15 +157,12 @@ class basic_table, Allocator>: internal::basic_common_table { using container_for = std::vector>; using container_type = std::tuple...>; - using underlying_type = internal::basic_common_table; public: /*! @brief Allocator type. */ using allocator_type = Allocator; - /*! @brief Base type. */ - using base_type = underlying_type; /*! @brief Unsigned integer type. */ - using size_type = typename base_type::size_type; + using size_type = std::size_t; /*! @brief Input iterator type. */ using iterator = internal::table_iterator::iterator...>; /*! @brief Constant input iterator type. */ @@ -248,7 +237,7 @@ public: * * @param cap Desired capacity. */ - void reserve(const size_type cap) override { + void reserve(const size_type cap) { (std::get>(payload.first()).reserve(cap), ...); } @@ -257,12 +246,12 @@ public: * space for. * @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(); } /*! @brief Requests the removal of unused capacity. */ - void shrink_to_fit() override { + void shrink_to_fit() { (std::get>(payload.first()).shrink_to_fit(), ...); } @@ -369,7 +358,11 @@ public: */ template std::tuple emplace(Args &&...args) { - return std::forward_as_tuple(std::get>(payload.first()).emplace_back(std::forward(args))...); + if constexpr(sizeof...(Args) == 0u) { + return std::forward_as_tuple(std::get>(payload.first()).emplace_back()...); + } else { + return std::forward_as_tuple(std::get>(payload.first()).emplace_back(std::forward(args))...); + } } /**