util/ReusableArray: add move constructor/operator

This commit is contained in:
Max Kellermann 2017-01-11 20:32:42 +01:00
parent 6778ff27ea
commit 3514fd2433

View File

@ -30,10 +30,12 @@
#ifndef REUSABLE_ARRAY_HXX
#define REUSABLE_ARRAY_HXX
#include <stddef.h>
#include "Compiler.h"
#include <utility>
#include <stddef.h>
/**
* Manager for a temporary array which grows as needed. This attempts
* to reduce the number of consecutive heap allocations and
@ -50,8 +52,15 @@ class ReusableArray {
public:
ReusableArray() = default;
ReusableArray(const ReusableArray &other) = delete;
ReusableArray &operator=(const ReusableArray &other) = delete;
ReusableArray(ReusableArray &&src)
:buffer(std::exchange(src.buffer, nullptr)),
capacity(std::exchange(src.capacity, 0)) {}
ReusableArray &operator=(const ReusableArray &&src) {
std::swap(buffer, src.buffer);
std::swap(capacity, src.capacity);
return *this;
}
~ReusableArray() {
delete[] buffer;