diff --git a/src/util/AllocatedArray.hxx b/src/util/AllocatedArray.hxx index aaa788420..fc6400014 100644 --- a/src/util/AllocatedArray.hxx +++ b/src/util/AllocatedArray.hxx @@ -61,16 +61,17 @@ public: explicit AllocatedArray(size_type _size) noexcept :buffer{new T[_size], _size} {} - explicit AllocatedArray(const AllocatedArray &other) noexcept { - assert(other.size() == 0 || other.buffer.data != nullptr); - - if (other == nullptr) + explicit AllocatedArray(ConstBuffer src) noexcept { + if (src == nullptr) return; - buffer = {new T[other.buffer.size], other.buffer.size}; - std::copy_n(other.buffer.data, buffer.size, buffer.data); + buffer = {new T[src.size], src.size}; + std::copy_n(src.data, src.size, buffer.data); } + explicit AllocatedArray(const AllocatedArray &other) noexcept + :AllocatedArray(other.buffer) {} + AllocatedArray(AllocatedArray &&other) noexcept :buffer(std::exchange(other.buffer, nullptr)) {} @@ -78,6 +79,15 @@ public: delete[] buffer.data; } + AllocatedArray &operator=(ConstBuffer src) noexcept { + assert(size() == 0 || buffer.data != nullptr); + assert(src.size == 0 || src.data != nullptr); + + ResizeDiscard(src.size); + std::copy_n(src.data, src.size, buffer.data); + return *this; + } + AllocatedArray &operator=(const AllocatedArray &other) noexcept { assert(size() == 0 || buffer.data != nullptr); assert(other.size() == 0 || other.buffer.data != nullptr);