util/ReusableArray: add move constructor/operator
This commit is contained in:
parent
6778ff27ea
commit
3514fd2433
@ -30,10 +30,12 @@
|
|||||||
#ifndef REUSABLE_ARRAY_HXX
|
#ifndef REUSABLE_ARRAY_HXX
|
||||||
#define REUSABLE_ARRAY_HXX
|
#define REUSABLE_ARRAY_HXX
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for a temporary array which grows as needed. This attempts
|
* Manager for a temporary array which grows as needed. This attempts
|
||||||
* to reduce the number of consecutive heap allocations and
|
* to reduce the number of consecutive heap allocations and
|
||||||
@ -50,8 +52,15 @@ class ReusableArray {
|
|||||||
public:
|
public:
|
||||||
ReusableArray() = default;
|
ReusableArray() = default;
|
||||||
|
|
||||||
ReusableArray(const ReusableArray &other) = delete;
|
ReusableArray(ReusableArray &&src)
|
||||||
ReusableArray &operator=(const ReusableArray &other) = delete;
|
: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() {
|
~ReusableArray() {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
Loading…
Reference in New Issue
Block a user