Ring buffer: Add swap function, make move (swap) assignment noexcept

This commit is contained in:
Jonathan G Rennison
2023-08-19 12:16:33 +01:00
parent ab128143fb
commit 8d2911fe29

View File

@@ -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;