[util] Add move & copy constructors to small_vector

This commit is contained in:
Robin Kertels 2024-03-13 15:49:01 +01:00
parent b948591ef6
commit 260ec73b37
No known key found for this signature in database
GPG Key ID: 3824904F14D40757
1 changed files with 34 additions and 5 deletions

View File

@ -13,8 +13,37 @@ namespace dxvk {
small_vector() { }
small_vector (const small_vector&) = delete;
small_vector& operator = (const small_vector&) = delete;
small_vector(const small_vector& other) {
reserve(other.m_size);
for (size_t i = 0; i < other.m_size; i++) {
*ptr(i) = *other.ptr(i);
}
m_size = other.m_size;
};
small_vector& operator = (const small_vector& other) {
for (size_t i = 0; i < m_size; i++)
ptr(i)->~T();
reserve(other.m_size);
for (size_t i = 0; i < other.m_size; i++) {
*ptr(i) = *other.ptr(i);
}
m_size = other.m_size;
};
small_vector(small_vector&& other) {
if (other.m_capacity == N) {
for (size_t i = 0; i < other.m_size; i++) {
u.m_data[i] = std::move(other.u.m_data[i]);
}
} else {
u.m_ptr = other.u.m_ptr;
other.m_capacity = N;
}
m_size = other.m_size;
other.m_size = 0;
}
~small_vector() {
for (size_t i = 0; i < m_size; i++)