From 8d2911fe29eaf5cf0e8b08ca3438120475abfcd8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 19 Aug 2023 12:16:33 +0100 Subject: [PATCH] Ring buffer: Add swap function, make move (swap) assignment noexcept --- src/core/ring_buffer.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/ring_buffer.hpp b/src/core/ring_buffer.hpp index 96190d6772..7cac50648e 100644 --- a/src/core/ring_buffer.hpp +++ b/src/core/ring_buffer.hpp @@ -227,7 +227,7 @@ public: } } - ring_buffer(ring_buffer &&other) + ring_buffer(ring_buffer &&other) noexcept { std::swap(this->data, other.data); std::swap(this->head, other.head); @@ -264,7 +264,7 @@ public: return *this; } - ring_buffer& operator =(ring_buffer &&other) + ring_buffer& operator =(ring_buffer &&other) noexcept { if (&other != this) { std::swap(this->data, other.data); @@ -282,6 +282,14 @@ public: } } + void swap(ring_buffer &other) noexcept + { + std::swap(this->data, other.data); + std::swap(this->head, other.head); + std::swap(this->count, other.count); + std::swap(this->mask, other.mask); + } + bool operator ==(const ring_buffer& other) const { if (this->count != other.count) return false;