diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-03-19 14:22:12 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-03-19 14:22:12 +0100 |
| commit | cffc61472430e3c59630201f8f2698e9ce8c0733 (patch) | |
| tree | 2a9fb2a59090d5d3dc3a9fee4df2bc09f56a8730 /libs | |
| parent | 0decd023337694872e2d3a530b4a768049e59f5d (diff) | |
| download | teachos-cffc61472430e3c59630201f8f2698e9ce8c0733.tar.xz teachos-cffc61472430e3c59630201f8f2698e9ce8c0733.zip | |
kstd: apply minor cleanup to vector
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/include/kstd/vector | 21 |
1 files 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<value_type> list, allocator_type const & allocator = allocator_type{}) + vector(std::initializer_list<value_type> 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<allocator_type>::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<allocator_type>::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<allocator_type>::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<allocator_type>::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<allocator_type>::construct(m_allocator, to++, std::move(*from++)); } |
