From cffc61472430e3c59630201f8f2698e9ce8c0733 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 19 Mar 2026 14:22:12 +0100 Subject: kstd: apply minor cleanup to vector --- libs/kstd/include/kstd/vector | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector index 8e0377e..a897b47 100644 --- a/libs/kstd/include/kstd/vector +++ b/libs/kstd/include/kstd/vector @@ -194,7 +194,7 @@ namespace kstd //! Construct a new vector and initialize it's content by copying all elements in the given initializer list. //! //! @param list The initializer list containing the source objects. - explicit vector(std::initializer_list list, allocator_type const & allocator = allocator_type{}) + vector(std::initializer_list list, allocator_type const & allocator = allocator_type{}) : vector{std::ranges::begin(list), std::ranges::end(list), allocator} {} @@ -239,7 +239,7 @@ namespace kstd } else { - auto new_data = std::allocator_traits::allocate(m_allocator, other.size()); + auto new_data = allocate_n(other.size()); uninitialized_copy_with_allocator(other.begin(), new_data, other.size()); clear_and_deallocate(); m_data = new_data; @@ -297,7 +297,7 @@ namespace kstd } else { - auto new_data = std::allocator_traits::allocate(get_allocator(), other.size()); + auto new_data = allocate_n(other.size()); uninitialized_move_with_allocator(other.begin(), new_data, other.size()); clear_and_deallocate(); m_data = new_data; @@ -520,12 +520,9 @@ namespace kstd auto new_data = allocate_n(new_capacity); auto old_size = size(); - for (auto i = 0uz; i < old_size; ++i) - { - std::allocator_traits::construct(m_allocator, new_data + i, std::move((*this)[i])); - } + uninitialized_move_with_allocator(begin(), new_data, size()); clear_and_deallocate(); - std::exchange(m_data, new_data); + m_data = new_data; m_capacity = new_capacity; m_size = old_size; } @@ -660,17 +657,17 @@ namespace kstd } } - constexpr auto uninitialized_copy_with_allocator(const_iterator from, iterator to, difference_type count) + constexpr auto uninitialized_copy_with_allocator(const_iterator from, iterator to, size_type count) { - for (auto i = 0z; i < count; ++i) + for (auto i = 0uz; i < count; ++i) { std::allocator_traits::construct(m_allocator, to++, *from++); } } - constexpr auto uninitialized_move_with_allocator(iterator from, iterator to, difference_type count) + constexpr auto uninitialized_move_with_allocator(iterator from, iterator to, size_type count) { - for (auto i = 0z; i < count; ++i) + for (auto i = 0uz; i < count; ++i) { std::allocator_traits::construct(m_allocator, to++, std::move(*from++)); } -- cgit v1.2.3