From 822090f30932b6e1ebc23f45513c45db81f982b3 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 25 Jun 2023 17:21:29 -0500 Subject: [PATCH] [ox/std] Make Vector functions also noexcept for pointers --- deps/ox/src/ox/std/vector.hpp | 70 +++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 325e8780..3547e2f9 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -236,6 +236,7 @@ class Vector: detail::VectorAllocator { private: static constexpr auto initialCap = SmallVectorSize > 0 ? SmallVectorSize : 50; + static constexpr auto useNoexcept = ox::is_integral_v || ox::is_pointer_v; std::size_t m_size = 0; std::size_t m_cap = 0; T *m_items = nullptr; @@ -247,7 +248,7 @@ class Vector: detail::VectorAllocator { constexpr Vector(std::initializer_list list) noexcept; - constexpr Vector(const Vector &other) noexcept(ox::is_integral_v); + constexpr Vector(const Vector &other) noexcept(useNoexcept); constexpr Vector(Vector &&other) noexcept; @@ -311,9 +312,9 @@ class Vector: detail::VectorAllocator { return iterator(m_items, MaxValue, m_size); } - constexpr bool operator==(const Vector &other) const noexcept(ox::is_integral_v); + constexpr bool operator==(const Vector &other) const noexcept(useNoexcept); - constexpr Vector &operator=(const Vector &other) noexcept(ox::is_integral_v); + constexpr Vector &operator=(const Vector &other) noexcept(useNoexcept); constexpr Vector &operator=(Vector &&other) noexcept; @@ -339,9 +340,9 @@ class Vector: detail::VectorAllocator { [[nodiscard]] constexpr bool empty() const noexcept; - constexpr void clear() noexcept(ox::is_integral_v); + constexpr void clear() noexcept(useNoexcept); - constexpr void resize(std::size_t size) noexcept(ox::is_integral_v); + constexpr void resize(std::size_t size) noexcept(useNoexcept); [[nodiscard]] constexpr T *data() noexcept { @@ -354,36 +355,36 @@ class Vector: detail::VectorAllocator { } [[nodiscard]] - constexpr bool contains(const T&) const noexcept(ox::is_integral_v); + constexpr bool contains(const T&) const noexcept(useNoexcept); constexpr iterator<> insert( - std::size_t pos, std::size_t cnt, const T &val) noexcept(ox::is_integral_v); + std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept); - constexpr iterator<> insert(std::size_t pos, const T &val) noexcept(ox::is_integral_v); + constexpr iterator<> insert(std::size_t pos, const T &val) noexcept(useNoexcept); template - constexpr iterator<> emplace(std::size_t pos, Args&&... args) noexcept(ox::is_integral_v); + constexpr iterator<> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept); template - constexpr T &emplace_back(Args&&... args) noexcept(ox::is_integral_v); + constexpr T &emplace_back(Args&&... args) noexcept(useNoexcept); - constexpr void push_back(const T &item) noexcept(ox::is_integral_v); + constexpr void push_back(const T &item) noexcept(useNoexcept); - constexpr void pop_back() noexcept(ox::is_integral_v); + constexpr void pop_back() noexcept(useNoexcept); /** * Removes an item from the Vector. * @param pos iterator at the point to remove * @return Error if index is out of bounds */ - constexpr Result> erase(const iterator<> &pos) noexcept(ox::is_integral_v); + constexpr Result> erase(const iterator<> &pos) noexcept(useNoexcept); /** * Removes an item from the Vector. * @param pos position of item to remove * @return Error if index is out of bounds */ - constexpr Result> erase(std::size_t pos) noexcept(ox::is_integral_v); + constexpr Result> erase(std::size_t pos) noexcept(useNoexcept); /** * Moves the last item in the Vector to position pos and decrements the @@ -391,13 +392,13 @@ class Vector: detail::VectorAllocator { * @param pos position of item to remove * @return Error if index is out of bounds */ - constexpr Error unordered_erase(std::size_t pos) noexcept(ox::is_integral_v); + constexpr Error unordered_erase(std::size_t pos) noexcept(useNoexcept); - constexpr void reserve(std::size_t cap) noexcept(ox::is_integral_v); + constexpr void reserve(std::size_t cap) noexcept(useNoexcept); private: constexpr void reserveInsert( - std::size_t cap, std::size_t pos, std::size_t offset = 1) noexcept(ox::is_integral_v); + std::size_t cap, std::size_t pos, std::size_t offset = 1) noexcept(useNoexcept); }; @@ -429,7 +430,7 @@ constexpr Vector::Vector(std::initializer_list } template -constexpr Vector::Vector(const Vector &other) noexcept(ox::is_integral_v) { +constexpr Vector::Vector(const Vector &other) noexcept(useNoexcept) { m_size = other.m_size; m_cap = other.m_cap; this->allocate(&m_items, other.m_cap); @@ -458,7 +459,7 @@ constexpr Vector::~Vector() { template constexpr bool Vector::operator==( - const Vector &other) const noexcept(ox::is_integral_v) { + const Vector &other) const noexcept(useNoexcept) { if (m_size != other.m_size) { return false; } @@ -472,7 +473,7 @@ constexpr bool Vector::operator==( template constexpr Vector &Vector::operator=( - const Vector &other) noexcept(ox::is_integral_v) { + const Vector &other) noexcept(useNoexcept) { if (this != &other) { clear(); this->deallocate(m_items, m_cap); @@ -557,7 +558,7 @@ constexpr bool Vector::empty() const noexcept { } template -constexpr void Vector::clear() noexcept(ox::is_integral_v) { +constexpr void Vector::clear() noexcept(useNoexcept) { if constexpr(is_class()) { for (std::size_t i = 0; i < m_size; ++i) { m_items[i].~T(); @@ -567,7 +568,7 @@ constexpr void Vector::clear() noexcept(ox::is_in } template -constexpr void Vector::resize(std::size_t size) noexcept(ox::is_integral_v) { +constexpr void Vector::resize(std::size_t size) noexcept(useNoexcept) { if (m_cap < size) { reserve(size * 2); } @@ -584,7 +585,7 @@ constexpr void Vector::resize(std::size_t size) n } template -constexpr bool Vector::contains(const T &v) const noexcept(ox::is_integral_v) { +constexpr bool Vector::contains(const T &v) const noexcept(useNoexcept) { for (std::size_t i = 0; i < m_size; i++) { if (m_items[i] == v) { return true; @@ -596,7 +597,7 @@ constexpr bool Vector::contains(const T &v) const template constexpr typename Vector::template iterator<> Vector::insert( - std::size_t pos, std::size_t cnt, const T &val) noexcept(ox::is_integral_v) { + std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept) { if (m_size + cnt > m_cap) { reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt); if (pos < m_size) { @@ -624,7 +625,7 @@ Vector::insert( template constexpr typename Vector::template iterator<> -Vector::insert(std::size_t pos, const T &val) noexcept(ox::is_integral_v) { +Vector::insert(std::size_t pos, const T &val) noexcept(useNoexcept) { if (m_size == m_cap) { reserveInsert(m_cap ? m_cap * 2 : initialCap, pos); if (pos < m_size) { @@ -649,7 +650,7 @@ Vector::insert(std::size_t pos, const T &val) noe template template constexpr typename Vector::template iterator<> -Vector::emplace(std::size_t pos, Args&&... args) noexcept(ox::is_integral_v) { +Vector::emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept) { if (m_size == m_cap) { reserveInsert(m_cap ? m_cap * 2 : initialCap); if (pos < m_size) { @@ -671,8 +672,7 @@ Vector::emplace(std::size_t pos, Args&&... args) template template -constexpr T &Vector::emplace_back(Args&&... args) -noexcept(ox::is_integral_v) { +constexpr T &Vector::emplace_back(Args&&... args) noexcept(useNoexcept) { if (m_size == m_cap) { reserve(m_cap ? m_cap * 2 : initialCap); } @@ -682,7 +682,7 @@ noexcept(ox::is_integral_v) { } template -constexpr void Vector::push_back(const T &item) noexcept(ox::is_integral_v) { +constexpr void Vector::push_back(const T &item) noexcept(useNoexcept) { if (m_size == m_cap) { reserve(m_cap ? m_cap * 2 : initialCap); } @@ -691,20 +691,20 @@ constexpr void Vector::push_back(const T &item) n } template -constexpr void Vector::pop_back() noexcept(ox::is_integral_v) { +constexpr void Vector::pop_back() noexcept(useNoexcept) { --m_size; m_items[m_size].~T(); } template constexpr Result::template iterator> -Vector::erase(const iterator<> &pos) noexcept(ox::is_integral_v) { +Vector::erase(const iterator<> &pos) noexcept(useNoexcept) { return erase(pos.offset()); } template constexpr Result::template iterator> -Vector::erase(std::size_t pos) noexcept(ox::is_integral_v) { +Vector::erase(std::size_t pos) noexcept(useNoexcept) { if (pos >= m_size) { return OxError(1, "Vector::erase failed: pos is greater than Vector size"); } @@ -718,7 +718,7 @@ Vector::erase(std::size_t pos) noexcept(ox::is_in template constexpr Error Vector::unordered_erase(std::size_t pos) - noexcept(ox::is_integral_v) { + noexcept(useNoexcept) { if (pos >= m_size) { return OxError(1); } @@ -729,7 +729,7 @@ constexpr Error Vector::unordered_erase(std::size } template -constexpr void Vector::reserve(std::size_t cap) noexcept(ox::is_integral_v) { +constexpr void Vector::reserve(std::size_t cap) noexcept(useNoexcept) { if (cap <= m_cap) { return; } @@ -751,7 +751,7 @@ template constexpr void Vector::reserveInsert( std::size_t cap, std::size_t pos, - std::size_t offset) noexcept(ox::is_integral_v) { + std::size_t offset) noexcept(useNoexcept) { if (cap <= m_cap) { return; }