[ox/std] Add insert method to Vector
This commit is contained in:
parent
1d8f8566c5
commit
4011773374
14
deps/ox/src/ox/std/vector.hpp
vendored
14
deps/ox/src/ox/std/vector.hpp
vendored
@ -59,6 +59,8 @@ class Vector {
|
|||||||
|
|
||||||
bool contains(T) const noexcept;
|
bool contains(T) const noexcept;
|
||||||
|
|
||||||
|
void insert(std::size_t pos, const T &val) noexcept;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void emplace_back(Args&&... args) noexcept;
|
void emplace_back(Args&&... args) noexcept;
|
||||||
|
|
||||||
@ -215,6 +217,18 @@ bool Vector<T>::contains(T v) const noexcept {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Vector<T>::insert(std::size_t pos, const T &val) noexcept {
|
||||||
|
if (m_size == m_cap) {
|
||||||
|
expandCap(m_cap ? m_cap * 2 : 100);
|
||||||
|
}
|
||||||
|
for (auto i = m_size; i > pos; i--) {
|
||||||
|
m_items[i] = m_items[i - 1];
|
||||||
|
}
|
||||||
|
m_items[pos] = val;
|
||||||
|
++m_size;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void Vector<T>::emplace_back(Args&&... args) noexcept {
|
void Vector<T>::emplace_back(Args&&... args) noexcept {
|
||||||
|
Loading…
Reference in New Issue
Block a user