diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-01-18 23:42:56 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-01-18 23:45:00 +0100 |
commit | 3bf981d5130ba745df5b279af211caf5cc68d8a1 (patch) | |
tree | 12bb488cf8f09874d008f0732d62064d72b53334 /asl/buffer.hpp | |
parent | 9487f0e564bbb5163ad33860d82f2be16b7ab562 (diff) |
Add buffer resize
Diffstat (limited to 'asl/buffer.hpp')
-rw-r--r-- | asl/buffer.hpp | 30 |
1 files changed, 30 insertions, 0 deletions
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<typename... Args>
+ void resize_inner(isize_t new_size, Args&&... args)
+ requires constructible_from<T, Args&&...>
+ {
+ 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<T>(it, ASL_FWD(args)...);
+ }
+ }
+
public:
constexpr buffer() requires default_constructible<Allocator> = default;
@@ -324,6 +343,17 @@ public: store_size_encoded(encode_size_heap(current_size));
}
+ void resize(isize_t new_size)
+ requires default_constructible<T>
+ {
+ 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<T, decltype(args)&&...>
{
|