From ad00926e1ba625675a233243512e83f4d3cb1b97 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Jun 2021 12:55:01 +0200 Subject: [PATCH] util/AllocatedArray: add method release() --- src/util/AllocatedArray.hxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/AllocatedArray.hxx b/src/util/AllocatedArray.hxx index cbb128307..b85614fad 100644 --- a/src/util/AllocatedArray.hxx +++ b/src/util/AllocatedArray.hxx @@ -76,7 +76,7 @@ public: :AllocatedArray(other.buffer) {} AllocatedArray(AllocatedArray &&other) noexcept - :buffer(std::exchange(other.buffer, nullptr)) {} + :buffer(other.release()) {} ~AllocatedArray() noexcept { delete[] buffer.data; @@ -259,6 +259,13 @@ public: buffer.size = _size; } + + /** + * Give up ownership of the allocated buffer and return it. + */ + Buffer release() noexcept { + return std::exchange(buffer, nullptr); + } }; #endif