Commit a93b7172 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

util/AllocatedArray: add ConstBuffer copy constructor

parent 908b6a19
......@@ -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<T> 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<T> 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment