summaryrefslogtreecommitdiff
path: root/src/util/ReusableArray.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-11 20:32:42 +0100
committerMax Kellermann <max@musicpd.org>2017-01-11 20:37:12 +0100
commit3514fd2433ff2bc7553f52e8df55cd4c7a8c7b52 (patch)
tree1b4689aae270e735be85f033d6086efa9b967a1b /src/util/ReusableArray.hxx
parent6778ff27ea4f48393e3803266b414a45a9ef5a0d (diff)
util/ReusableArray: add move constructor/operator
Diffstat (limited to 'src/util/ReusableArray.hxx')
-rw-r--r--src/util/ReusableArray.hxx17
1 files 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 <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;