summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-03-09 15:32:33 -0500
committerAndreas Kling <kling@serenityos.org>2022-03-14 16:33:15 +0100
commitc12cfe83b72c8dab2bf0779acf906ce8ea0373d3 (patch)
tree29c02872a6db30c9dbcea55f34931ea6aacc62a9 /AK
parent5bb00a75f5f910ded566216713922caa704ce512 (diff)
downloadserenity-c12cfe83b72c8dab2bf0779acf906ce8ea0373d3.zip
AK: Allow creating a Vector from any Span of the same underlying type
This allows, for example, to create a Vector from a subset of another Vector.
Diffstat (limited to 'AK')
-rw-r--r--AK/Vector.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/Vector.h b/AK/Vector.h
index 9c81689d80..0f6bef5179 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -91,6 +91,13 @@ public:
m_size = other.size();
}
+ explicit Vector(Span<T const> other) requires(!IsLvalueReference<T>)
+ {
+ ensure_capacity(other.size());
+ TypedTransfer<StorageType>::copy(data(), other.data(), other.size());
+ m_size = other.size();
+ }
+
template<size_t other_inline_capacity>
Vector(Vector<T, other_inline_capacity> const& other)
{