From 47163e0f4eeabad9916cd7e73898b10be7ea645a Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 31 Oct 2022 22:30:15 +0200 Subject: [PATCH] Properly make vector::operator= not inline --- include/rstl/vector.hpp | 42 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/include/rstl/vector.hpp b/include/rstl/vector.hpp index 72e9b067..52a8cb79 100644 --- a/include/rstl/vector.hpp +++ b/include/rstl/vector.hpp @@ -77,22 +77,7 @@ public: ++x4_count; } - vector& operator=(const vector& other); /* { - if (this == &other) - return *this; - clear(); - if (other.size() == 0) { - x0_allocator.deallocate(xc_items); - x4_count = 0; - x8_capacity = 0; - xc_items = nullptr; - } else { - reserve(other.size()); - uninitialized_copy(other.data(), other.data() + other.size(), data()); - x4_count = other.x4_count; - } - return *this; - }*/ + vector& operator=(const vector& other); void clear() { destroy(begin(), end()); @@ -116,12 +101,12 @@ public: protected: template < typename In > void insert_into(iterator at, int n, In in) { - int insertAt = xc_items + n; - if (x8_capacity < insertAt) { + // int insertAt = xc_items + n; + // TODO: finish + if (x8_capacity < n) { int newCapacity = x8_capacity != 0 ? x8_capacity * 2 : 4; T* newData; x0_allocator.allocate(newData, newCapacity); - } } }; @@ -160,6 +145,25 @@ typename vector< T, Alloc >::iterator vector< T, Alloc >::insert(iterator it, co return begin() + diff; } +template < typename T, typename Alloc > +vector< T, Alloc >& vector< T, Alloc >::operator=(const vector< T, Alloc >& other) { + if (this == &other) + return *this; + clear(); + if (other.size() == 0) { + x0_allocator.deallocate(xc_items); + x4_count = 0; + x8_capacity = 0; + xc_items = nullptr; + } else { + reserve(other.size()); + uninitialized_copy(other.data(), other.data() + other.size(), data()); + x4_count = other.x4_count; + } + return *this; +} + + typedef vector< void > unk_vector; CHECK_SIZEOF(unk_vector, 0x10) } // namespace rstl