From 3514fd2433ff2bc7553f52e8df55cd4c7a8c7b52 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 11 Jan 2017 20:32:42 +0100 Subject: [PATCH] util/ReusableArray: add move constructor/operator --- src/util/ReusableArray.hxx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/util/ReusableArray.hxx b/src/util/ReusableArray.hxx index 26a7be50f..6e7e0dc4d 100644 --- a/src/util/ReusableArray.hxx +++ b/src/util/ReusableArray.hxx @@ -30,10 +30,12 @@ #ifndef REUSABLE_ARRAY_HXX #define REUSABLE_ARRAY_HXX -#include - #include "Compiler.h" +#include + +#include + /** * 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;