Skip to content

Commit

Permalink
fix vector.resize + vector(size) (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohoch authored Nov 21, 2024
1 parent 847b271 commit 6362f3a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions include/cista/containers/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 6362f3a

Please sign in to comment.