Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vector.resize for types without copy constructor #239

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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