[ox/std] Fix Vector insert functions
This commit is contained in:
parent
9e9f317c13
commit
a651d45a2f
48
deps/ox/src/ox/std/vector.hpp
vendored
48
deps/ox/src/ox/std/vector.hpp
vendored
@ -271,7 +271,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
constexpr bool contains(MaybeView_t<T> const&) const noexcept;
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept);
|
||||
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, T val) noexcept(useNoexcept);
|
||||
|
||||
@ -531,29 +531,23 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> co
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept) {
|
||||
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
if (pos < m_size) {
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
}
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size + cnt - 1; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
|
||||
}
|
||||
for (auto i = pos; i < pos + cnt; ++i) {
|
||||
m_items[i] = val;
|
||||
}
|
||||
} else {
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size + cnt - 1; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
for (auto i = 0u; i < cnt; ++i) {
|
||||
std::construct_at(&m_items[pos + i], m_items[pos]);
|
||||
}
|
||||
}
|
||||
++m_size;
|
||||
m_size += cnt;
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
@ -562,20 +556,14 @@ constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&,
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, T val) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
if (pos < m_size) {
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
std::construct_at(&m_items[pos], m_items[pos]);
|
||||
}
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
if (pos < m_size) {
|
||||
for (auto i = m_size; i > pos; --i) {
|
||||
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
|
||||
}
|
||||
m_items[pos] = std::move(val);
|
||||
} else {
|
||||
std::construct_at(&m_items[pos], m_items[pos]);
|
||||
}
|
||||
std::construct_at(&m_items[pos], std::move(val));
|
||||
}
|
||||
++m_size;
|
||||
return begin() + pos;
|
||||
|
Loading…
Reference in New Issue
Block a user