From 6618f8d9e775d58bf4dd39e51378f40913a9c7d0 Mon Sep 17 00:00:00 2001 From: Pablo Hoch Date: Thu, 21 Nov 2024 15:50:03 +0100 Subject: [PATCH] fix vector.resize + vector(size) --- include/cista/containers/vector.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/cista/containers/vector.h b/include/cista/containers/vector.h index 09cfb43d..9c2b479a 100644 --- a/include/cista/containers/vector.h +++ b/include/cista/containers/vector.h @@ -40,7 +40,13 @@ struct basic_vector { explicit basic_vector(allocator_type const&) noexcept {} basic_vector() noexcept = default; - explicit basic_vector(size_type const size, T init = T{}, + explicit basic_vector(size_type const size, + Allocator const& alloc = Allocator{}) { + CISTA_UNUSED_PARAM(alloc) + resize(size); + } + + explicit basic_vector(size_type const size, T init, Allocator const& alloc = Allocator{}) { CISTA_UNUSED_PARAM(alloc) resize(size, std::move(init)); @@ -300,7 +306,15 @@ struct basic_vector { return *ptr; } - void resize(size_type const size, T init = T{}) { + void resize(size_type const size) { + reserve(size); + for (auto i = used_size_; i < size; ++i) { + new (el_ + i) T{}; + } + used_size_ = size; + } + + void resize(size_type const size, T init) { reserve(size); for (auto i = used_size_; i < size; ++i) { new (el_ + i) T{init};