From 3bf981d5130ba745df5b279af211caf5cc68d8a1 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 18 Jan 2025 23:42:56 +0100 Subject: Add buffer resize --- asl/buffer.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'asl/buffer.hpp') diff --git a/asl/buffer.hpp b/asl/buffer.hpp index 9fd8162..aea1cb6 100644 --- a/asl/buffer.hpp +++ b/asl/buffer.hpp @@ -190,6 +190,25 @@ private: } } + template + void resize_inner(isize_t new_size, Args&&... args) + requires constructible_from + { + ASL_ASSERT(new_size >= 0); + + isize_t old_size = size(); + resize_uninit(new_size); + + T* data_ptr = data(); + T* end = data_ptr + new_size; + + // NOLINTNEXTLINE(*-pointer-arithmetic) + for (T* it = data_ptr + old_size; it < end; ++it) + { + construct_at(it, ASL_FWD(args)...); + } + } + public: constexpr buffer() requires default_constructible = default; @@ -324,6 +343,17 @@ public: store_size_encoded(encode_size_heap(current_size)); } + void resize(isize_t new_size) + requires default_constructible + { + resize_inner(new_size); + } + + void resize(isize_t new_size, const T& value) + { + resize_inner(new_size, value); + } + constexpr T& push(auto&&... args) requires constructible_from { -- cgit