aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/include/kstd/vector39
1 files changed, 39 insertions, 0 deletions
diff --git a/libs/kstd/include/kstd/vector b/libs/kstd/include/kstd/vector
index 9e41cb6..e51cbac 100644
--- a/libs/kstd/include/kstd/vector
+++ b/libs/kstd/include/kstd/vector
@@ -559,6 +559,45 @@ namespace kstd
m_size = old_size;
}
+ //! Resize this vector to contain @p new_size elements.
+ constexpr auto resize(size_type new_size) -> void
+ {
+ resize(new_size, value_type{});
+ }
+
+ //! Resize this vector to contain @p new_size elements, filling new elements with @p value.
+ constexpr auto resize(size_type new_size, const_reference value) -> void
+ {
+ if (new_size < size())
+ {
+ destroy_n(begin() + new_size, size() - new_size);
+ m_size = new_size;
+ return;
+ }
+
+ if (new_size == size())
+ {
+ return;
+ }
+
+ if (new_size > max_size())
+ {
+ kstd::os::panic("[kstd:vector] Tried to resize more space than theoretically possible.");
+ }
+
+ if (new_size > capacity())
+ {
+ reserve(new_size);
+ }
+
+ for (auto i = size(); i < new_size; ++i)
+ {
+ std::allocator_traits<allocator_type>::construct(m_allocator, m_data + i, value);
+ }
+
+ m_size = new_size;
+ }
+
//! Get the number of element this vector has currently space for, including elements currently in this vector.
[[nodiscard]] constexpr auto capacity() const noexcept -> size_type
{