From 7e66d8e7e50060553be837b021aef1d83d0252bd Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 1 Jan 2025 19:40:06 +0100 Subject: Implement move assign for buffer --- asl/buffer.hpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'asl/buffer.hpp') diff --git a/asl/buffer.hpp b/asl/buffer.hpp index 84284bc..276222d 100644 --- a/asl/buffer.hpp +++ b/asl/buffer.hpp @@ -111,15 +111,8 @@ private: } } -public: - constexpr buffer() requires default_constructible = default; - - explicit constexpr buffer(Allocator allocator) - : m_allocator{ASL_MOVE(allocator)} - {} - - constexpr buffer(buffer&& other) - : buffer(ASL_MOVE(other.m_allocator)) + // NOLINTNEXTLINE(*-rvalue-reference-param-not-moved) + void move_from_other(buffer&& other) { if (other.is_on_heap()) { @@ -142,6 +135,30 @@ public: other.set_size_inline(0); } +public: + constexpr buffer() requires default_constructible = default; + + explicit constexpr buffer(Allocator allocator) + : m_allocator{ASL_MOVE(allocator)} + {} + + constexpr buffer(buffer&& other) + : buffer(ASL_MOVE(other.m_allocator)) + { + move_from_other(ASL_MOVE(other)); + } + + constexpr buffer& operator=(buffer&& other) + { + if (&other == this) { return *this; } + + destroy(); + m_allocator = ASL_MOVE(other.m_allocator); + move_from_other(ASL_MOVE(other)); + + return *this; + } + ~buffer() { destroy(); -- cgit