From 68a0dd9660dd735931bd7f27bf65c52e21ca29c0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 30 Nov 2023 21:28:11 -0600 Subject: [PATCH] [ox/std] Give Vector MaybeSV in places where it makes sense --- deps/ox/src/ox/std/vector.hpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 0b588a6b..ab9feba0 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -16,7 +16,7 @@ #include "iterator.hpp" #include "math.hpp" #include "memory.hpp" -#include "new.hpp" +#include "stringview.hpp" #include "types.hpp" #include "utility.hpp" @@ -254,12 +254,12 @@ class Vector: detail::VectorAllocator { } [[nodiscard]] - constexpr bool contains(const T&) const noexcept(useNoexcept); + constexpr bool contains(MaybeSV_t const&) const noexcept(useNoexcept); constexpr iterator insert( - std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept); + std::size_t pos, std::size_t cnt, MaybeSV_t const&val) noexcept(useNoexcept); - constexpr iterator insert(std::size_t pos, const T &val) noexcept(useNoexcept); + constexpr iterator insert(std::size_t pos, MaybeSV_t const&val) noexcept(useNoexcept); template constexpr iterator emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept); @@ -267,7 +267,9 @@ class Vector: detail::VectorAllocator { template constexpr T &emplace_back(Args&&... args) noexcept(useNoexcept); - constexpr void push_back(const T &item) noexcept(useNoexcept); + constexpr void push_back(T &&item) noexcept(useNoexcept); + + constexpr void push_back(MaybeSV_t const&item) noexcept(useNoexcept); constexpr void pop_back() noexcept(useNoexcept); @@ -484,7 +486,7 @@ constexpr void Vector::resize(std::size_t size) n } template -constexpr bool Vector::contains(const T &v) const noexcept(useNoexcept) { +constexpr bool Vector::contains(MaybeSV_t const&v) const noexcept(useNoexcept) { for (std::size_t i = 0; i < m_size; i++) { if (m_items[i] == v) { return true; @@ -496,7 +498,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(useNoexcept) { + std::size_t pos, std::size_t cnt, MaybeSV_t const&val) noexcept(useNoexcept) { if (m_size + cnt > m_cap) { reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt); if (pos < m_size) { @@ -524,7 +526,7 @@ Vector::insert( template constexpr typename Vector::template iterator -Vector::insert(std::size_t pos, const T &val) noexcept(useNoexcept) { +Vector::insert(std::size_t pos, MaybeSV_t const&val) noexcept(useNoexcept) { if (m_size == m_cap) { reserveInsert(m_cap ? m_cap * 2 : initialCap, pos); if (pos < m_size) { @@ -581,7 +583,16 @@ constexpr T &Vector::emplace_back(Args&&... args) } template -constexpr void Vector::push_back(const T &item) noexcept(useNoexcept) { +constexpr void Vector::push_back(T &&item) noexcept(useNoexcept) { + if (m_size == m_cap) { + reserve(m_cap ? m_cap * 2 : initialCap); + } + std::construct_at(&m_items[m_size], std::move(item)); + ++m_size; +} + +template +constexpr void Vector::push_back(MaybeSV_t const&item) noexcept(useNoexcept) { if (m_size == m_cap) { reserve(m_cap ? m_cap * 2 : initialCap); }