[ox/std] Add insert method to Vector

This commit is contained in:
Gary Talent 2020-03-29 13:32:17 -05:00
parent 1d8f8566c5
commit 4011773374

View File

@ -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 {