From 6dec88c7fa956d0a7f79cc21df61d18fcaedfdb4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Jan 2020 10:57:30 +0100 Subject: [PATCH] AK: Allow copying a Vector from a Vector with different inline capacity --- AK/Vector.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index daf3cd0a558..194e043053b 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -146,6 +146,14 @@ public: m_size = other.size(); } + template + Vector(const Vector& other) + { + ensure_capacity(other.size()); + TypedTransfer::copy(data(), other.data(), other.size()); + m_size = other.size(); + } + // FIXME: What about assigning from a vector with lower inline capacity? Vector& operator=(Vector&& other) { @@ -329,6 +337,16 @@ public: return *this; } + template + Vector& operator=(const Vector& other) + { + clear(); + ensure_capacity(other.size()); + TypedTransfer::copy(data(), other.data(), other.size()); + m_size = other.size(); + return *this; + } + void append(Vector&& other) { if (is_empty()) {