Avoid throwing while relocating Deque contents

This commit is contained in:
sfc-gh-tclinkenbeard 2020-07-10 11:42:56 -07:00
parent 32d76fcff1
commit da28face2c
1 changed files with 3 additions and 2 deletions

View File

@ -168,10 +168,11 @@ private:
if (newSize > max_size()) throw std::bad_alloc();
//printf("Growing to %lld (%u-%u mask %u)\n", (long long)newSize, begin, end, mask);
T* newArr = (T*)aligned_alloc(std::max(__alignof(T), sizeof(void*)),
newSize * sizeof(T)); // SOMEDAY: FastAllocator, exception safety
newSize * sizeof(T)); // SOMEDAY: FastAllocator
ASSERT(newArr != nullptr);
for (int i = begin; i != end; i++) {
new (&newArr[i - begin]) T(std::move(arr[i&mask]));
new (&newArr[i - begin]) T(std::move_if_noexcept(arr[i & mask]));
static_assert(std::is_nothrow_destructible_v<T>);
arr[i&mask].~T();
}
aligned_free(arr);