From 9d74eca4366c0c4da95bd42615de5c8fe4b8e126 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 10 Apr 2022 03:03:07 -0500 Subject: [PATCH] [ox/std] Use std::construct_at in Vector instead placement new --- deps/ox/src/ox/std/vector.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index a9ba0a86..a699d1f0 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -387,7 +387,7 @@ constexpr Vector::Vector(std::size_t size) noexcept { m_cap = m_size; this->allocate(&m_items, m_cap); for (std::size_t i = 0; i < size; ++i) { - m_items[i] = {}; + std::construct_at(&m_items[i]); } } @@ -404,7 +404,7 @@ constexpr Vector::Vector(const Vector &other) { m_cap = other.m_cap; this->allocate(&m_items, other.m_cap); for (std::size_t i = 0; i < m_size; ++i) { - new (&m_items[i]) T(other.m_items[i]); + std::construct_at(&m_items[i], other.m_items[i]); } } @@ -449,7 +449,7 @@ constexpr Vector &Vector::operator=(cons m_cap = other.m_cap; this->allocate(&m_items, other.m_cap); for (std::size_t i = 0; i < m_size; i++) { - new (&m_items[i]) T(other.m_items[i]); + std::construct_at(&m_items[i], other.m_items[i]); } } return *this; @@ -544,7 +544,7 @@ constexpr void Vector::resize(std::size_t size) { } if (m_size < size) { for (std::size_t i = m_size; i < size; i++) { - new (&m_items[i]) T(); + std::construct_at(&m_items[i]); } } else { for (std::size_t i = size; i < m_size; i++) { @@ -572,11 +572,11 @@ constexpr void Vector::insert(std::size_t pos, const T &val) } if (pos < m_size) { for (auto i = m_size; i > pos; --i) { - new(&m_items[i]) T(std::move(m_items[i - 1])); + std::construct_at(&m_items[i], std::move(m_items[i - 1])); } m_items[pos] = val; } else { - new(&m_items[pos]) T(val); + std::construct_at(&m_items[pos], val); } ++m_size; } @@ -587,7 +587,7 @@ constexpr T &Vector::emplace_back(Args&&... args) { if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : initialSize); } - auto out = new (&m_items[m_size]) T{forward(args)...}; + auto out = std::construct_at(&m_items[m_size], forward(args)...); ++m_size; return *out; } @@ -597,7 +597,7 @@ constexpr void Vector::push_back(const T &item) { if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : initialSize); } - new (&m_items[m_size]) T(item); + std::construct_at(&m_items[m_size], item); ++m_size; } @@ -645,7 +645,7 @@ constexpr void Vector::expandCap(std::size_t cap) { if (oldItems) { // move over old items const auto itRange = ox::min(cap, m_size); for (std::size_t i = 0; i < itRange; ++i) { - new (&m_items[i]) T(std::move(oldItems[i])); + std::construct_at(&m_items[i], std::move(oldItems[i])); oldItems[i].~T(); } this->deallocate(oldItems, oldCap);