From 4011773374b932ef5fc7565111d97063bb93dcdd Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 29 Mar 2020 13:32:17 -0500 Subject: [PATCH] [ox/std] Add insert method to Vector --- deps/ox/src/ox/std/vector.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 45c86eb5..ab45828f 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -59,6 +59,8 @@ class Vector { bool contains(T) const noexcept; + void insert(std::size_t pos, const T &val) noexcept; + template void emplace_back(Args&&... args) noexcept; @@ -215,6 +217,18 @@ bool Vector::contains(T v) const noexcept { return false; } +template +void Vector::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 template void Vector::emplace_back(Args&&... args) noexcept {