mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Merge pull request #991 from nogitsune-youkai/vectorFix
Fix exception safety in util::stack_vector::push_back
This commit is contained in:
commit
bac0d43fd7
1 changed files with 13 additions and 9 deletions
|
|
@ -48,21 +48,25 @@ namespace util {
|
|||
}
|
||||
|
||||
void push_back(const T& value) {
|
||||
if (size_ < capacity) {
|
||||
auto data = reinterpret_cast<char*>(data_.ptr() + (size_++));
|
||||
new (data) T(value);
|
||||
} else {
|
||||
if (size_ >= capacity) {
|
||||
throw std::overflow_error("stack vector capacity exceeded");
|
||||
}
|
||||
|
||||
void* p = data_.data + size_ * sizeof(T);
|
||||
::new (p) T(value);
|
||||
|
||||
++size_;
|
||||
}
|
||||
|
||||
void push_back(T&& value) {
|
||||
if (size_ < capacity) {
|
||||
auto data = reinterpret_cast<char*>(data_.ptr() + (size_++));
|
||||
new (data) T(std::move(value));
|
||||
} else {
|
||||
if (size_ >= capacity) {
|
||||
throw std::overflow_error("stack vector capacity exceeded");
|
||||
}
|
||||
|
||||
void* p = data_.data + size_ * sizeof(T);
|
||||
::new (p) T(std::move(value));
|
||||
|
||||
++size_;
|
||||
}
|
||||
|
||||
void pop_back() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue