浏览代码

AK: Allow copying a Vector from a Vector with different inline capacity

Andreas Kling 5 年之前
父节点
当前提交
6dec88c7fa
共有 1 个文件被更改,包括 18 次插入0 次删除
  1. 18 0
      AK/Vector.h

+ 18 - 0
AK/Vector.h

@@ -146,6 +146,14 @@ public:
         m_size = other.size();
     }
 
+    template<int other_inline_capacity>
+    Vector(const Vector<T, other_inline_capacity>& other)
+    {
+        ensure_capacity(other.size());
+        TypedTransfer<T>::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<int other_inline_capacity>
+    Vector& operator=(const Vector<T, other_inline_capacity>& other)
+    {
+        clear();
+        ensure_capacity(other.size());
+        TypedTransfer<T>::copy(data(), other.data(), other.size());
+        m_size = other.size();
+        return *this;
+    }
+
     void append(Vector&& other)
     {
         if (is_empty()) {