From a9f254dcea5cc73112ba4df96ceaf48a33fae216 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 2 Jan 2025 19:37:41 +0100 Subject: Implement copy move & assign for buffer --- asl/memory.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'asl/memory.hpp') diff --git a/asl/memory.hpp b/asl/memory.hpp index 1209bf6..209f1d1 100644 --- a/asl/memory.hpp +++ b/asl/memory.hpp @@ -56,6 +56,40 @@ constexpr void destroy_n(T* data, isize_t n) } } +template +constexpr void copy_uninit_n(T* to, const T* from, isize_t n) +{ + if constexpr (trivially_copy_constructible) + { + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + construct_at(to + i, from[i]); + } + } +} + +template +constexpr void copy_assign_n(T* to, const T* from, isize_t n) +{ + if constexpr (trivially_copy_constructible) + { + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + to[i] = from[i]; + } + } +} + template constexpr void relocate_uninit_n(T* to, T* from, isize_t n) { -- cgit