diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-01-01 19:40:06 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-01-01 19:40:06 +0100 |
commit | 7e66d8e7e50060553be837b021aef1d83d0252bd (patch) | |
tree | 855dd59082f1aacda77a58054e75a4522887f240 /asl/buffer.hpp | |
parent | 22131693e1892c5477c998ab63bf476d152b17cb (diff) |
Implement move assign for buffer
Diffstat (limited to 'asl/buffer.hpp')
-rw-r--r-- | asl/buffer.hpp | 35 |
1 files changed, 26 insertions, 9 deletions
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<Allocator> = 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<Allocator> = 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();
|