diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 2e3a887b..07d9752b 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -217,13 +217,13 @@ class Vector: detail::SmallVector { public: constexpr Vector() noexcept = default; - explicit Vector(std::size_t size) noexcept; + explicit constexpr Vector(std::size_t size) noexcept; - Vector(std::initializer_list list) noexcept; + constexpr Vector(std::initializer_list list) noexcept; - Vector(const Vector &other); + constexpr Vector(const Vector &other); - Vector(Vector &&other) noexcept; + constexpr Vector(Vector &&other) noexcept; ~Vector(); @@ -259,7 +259,7 @@ class Vector: detail::SmallVector { return iterator(m_items, MaxValue, m_size); } - bool operator==(const Vector &other) const; + constexpr bool operator==(const Vector &other) const; constexpr Vector &operator=(const Vector &other); @@ -281,9 +281,9 @@ class Vector: detail::SmallVector { constexpr std::size_t size() const noexcept; [[nodiscard]] - bool empty() const noexcept; + constexpr bool empty() const noexcept; - void clear(); + constexpr void clear(); constexpr void resize(std::size_t size); @@ -298,16 +298,16 @@ class Vector: detail::SmallVector { } [[nodiscard]] - bool contains(const T&) const; + constexpr bool contains(const T&) const; - void insert(std::size_t pos, const T &val); + constexpr void insert(std::size_t pos, const T &val); template - T &emplace_back(Args&&... args); + constexpr T &emplace_back(Args&&... args); - void push_back(const T &item); + constexpr void push_back(const T &item); - void pop_back(); + constexpr void pop_back(); /** * Removes an item from the Vector. @@ -315,14 +315,14 @@ class Vector: detail::SmallVector { * @return Error if index is out of bounds */ template - Error erase(const iterator &pos); + constexpr Error erase(const iterator &pos); /** * Removes an item from the Vector. * @param pos position of item to remove * @return Error if index is out of bounds */ - Error erase(std::size_t pos); + constexpr Error erase(std::size_t pos); /** * Moves the last item in the Vector to position pos and decrements the @@ -330,10 +330,10 @@ class Vector: detail::SmallVector { * @param pos position of item to remove * @return Error if index is out of bounds */ - Error unordered_erase(std::size_t pos); + constexpr Error unordered_erase(std::size_t pos); private: - void expandCap(std::size_t cap); + constexpr void expandCap(std::size_t cap); }; @@ -341,12 +341,12 @@ template::template iterator; template -VectorIt operator+(std::size_t n, const VectorIt &a) { +constexpr VectorIt operator+(std::size_t n, const VectorIt &a) { return a + n; } template -Vector::Vector(std::size_t size) noexcept { +constexpr Vector::Vector(std::size_t size) noexcept { m_size = size; m_cap = m_size; this->initItems(&m_items, m_cap); @@ -356,14 +356,14 @@ Vector::Vector(std::size_t size) noexcept { } template -Vector::Vector(std::initializer_list list) noexcept { +constexpr Vector::Vector(std::initializer_list list) noexcept { for (auto &item : list) { emplace_back(item); } } template -Vector::Vector(const Vector &other) { +constexpr Vector::Vector(const Vector &other) { m_size = other.m_size; m_cap = other.m_cap; this->initItems(&m_items, other.m_cap); @@ -373,7 +373,7 @@ Vector::Vector(const Vector &other) { } template -Vector::Vector(Vector &&other) noexcept { +constexpr Vector::Vector(Vector &&other) noexcept { m_size = other.m_size; m_cap = other.m_cap; m_items = other.m_items; @@ -391,7 +391,7 @@ Vector::~Vector() { } template -bool Vector::operator==(const Vector &other) const { +constexpr bool Vector::operator==(const Vector &other) const { if (m_size != other.m_size) { return false; } @@ -487,12 +487,12 @@ constexpr std::size_t Vector::size() const noexcept { } template -bool Vector::empty() const noexcept { +constexpr bool Vector::empty() const noexcept { return !m_size; } template -void Vector::clear() { +constexpr void Vector::clear() { if constexpr(is_class()) { for (std::size_t i = 0; i < m_size; ++i) { m_items[i].~T(); @@ -519,7 +519,7 @@ constexpr void Vector::resize(std::size_t size) { } template -bool Vector::contains(const T &v) const { +constexpr bool Vector::contains(const T &v) const { for (std::size_t i = 0; i < m_size; i++) { if (m_items[i] == v) { return true; @@ -529,7 +529,7 @@ bool Vector::contains(const T &v) const { } template -void Vector::insert(std::size_t pos, const T &val) { +constexpr void Vector::insert(std::size_t pos, const T &val) { // TODO: insert should ideally have its own expandCap if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : 100); @@ -543,7 +543,7 @@ void Vector::insert(std::size_t pos, const T &val) { template template -T &Vector::emplace_back(Args&&... args) { +constexpr T &Vector::emplace_back(Args&&... args) { if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : 100); } @@ -553,7 +553,7 @@ T &Vector::emplace_back(Args&&... args) { } template -void Vector::push_back(const T &item) { +constexpr void Vector::push_back(const T &item) { if (m_size == m_cap) { expandCap(m_cap ? m_cap * 2 : 100); } @@ -562,19 +562,19 @@ void Vector::push_back(const T &item) { } template -void Vector::pop_back() { +constexpr void Vector::pop_back() { --m_size; m_items[m_size].~T(); } template template -Error Vector::erase(const iterator &pos) { +constexpr Error Vector::erase(const iterator &pos) { return erase(pos.offset()); } template -Error Vector::erase(std::size_t pos) { +constexpr Error Vector::erase(std::size_t pos) { if (pos >= m_size) { return OxError(1); } @@ -586,7 +586,7 @@ Error Vector::erase(std::size_t pos) { } template -Error Vector::unordered_erase(std::size_t pos) { +constexpr Error Vector::unordered_erase(std::size_t pos) { if (pos >= m_size) { return OxError(1); } @@ -596,7 +596,7 @@ Error Vector::unordered_erase(std::size_t pos) { } template -void Vector::expandCap(std::size_t cap) { +constexpr void Vector::expandCap(std::size_t cap) { auto oldItems = m_items; m_cap = cap; this->initItems(&m_items, cap);