[ox/std] Give Vector MaybeSV in places where it makes sense
This commit is contained in:
parent
d635a954fa
commit
68a0dd9660
29
deps/ox/src/ox/std/vector.hpp
vendored
29
deps/ox/src/ox/std/vector.hpp
vendored
@ -16,7 +16,7 @@
|
|||||||
#include "iterator.hpp"
|
#include "iterator.hpp"
|
||||||
#include "math.hpp"
|
#include "math.hpp"
|
||||||
#include "memory.hpp"
|
#include "memory.hpp"
|
||||||
#include "new.hpp"
|
#include "stringview.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
@ -254,12 +254,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool contains(const T&) const noexcept(useNoexcept);
|
constexpr bool contains(MaybeSV_t<T> const&) const noexcept(useNoexcept);
|
||||||
|
|
||||||
constexpr iterator<T&, T*, false> insert(
|
constexpr iterator<T&, T*, false> insert(
|
||||||
std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept);
|
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||||
|
|
||||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, const T &val) noexcept(useNoexcept);
|
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||||
@ -267,7 +267,9 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
constexpr T &emplace_back(Args&&... args) noexcept(useNoexcept);
|
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<T> const&item) noexcept(useNoexcept);
|
||||||
|
|
||||||
constexpr void pop_back() noexcept(useNoexcept);
|
constexpr void pop_back() noexcept(useNoexcept);
|
||||||
|
|
||||||
@ -484,7 +486,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::resize(std::size_t size) n
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(const T &v) const noexcept(useNoexcept) {
|
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> const&v) const noexcept(useNoexcept) {
|
||||||
for (std::size_t i = 0; i < m_size; i++) {
|
for (std::size_t i = 0; i < m_size; i++) {
|
||||||
if (m_items[i] == v) {
|
if (m_items[i] == v) {
|
||||||
return true;
|
return true;
|
||||||
@ -496,7 +498,7 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(const T &v) const
|
|||||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||||
std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept) {
|
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||||
if (m_size + cnt > m_cap) {
|
if (m_size + cnt > m_cap) {
|
||||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||||
if (pos < m_size) {
|
if (pos < m_size) {
|
||||||
@ -524,7 +526,7 @@ Vector<T, SmallVectorSize, Allocator>::insert(
|
|||||||
|
|
||||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, const T &val) noexcept(useNoexcept) {
|
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||||
if (m_size == m_cap) {
|
if (m_size == m_cap) {
|
||||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||||
if (pos < m_size) {
|
if (pos < m_size) {
|
||||||
@ -581,7 +583,16 @@ constexpr T &Vector<T, SmallVectorSize, Allocator>::emplace_back(Args&&... args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(const T &item) noexcept(useNoexcept) {
|
constexpr void Vector<T, SmallVectorSize, Allocator>::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<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||||
|
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept) {
|
||||||
if (m_size == m_cap) {
|
if (m_size == m_cap) {
|
||||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user