From cc5e222be5545d3fd02e61cf0a0afb50407c2578 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sun, 3 Jan 2021 00:32:01 -0800 Subject: [PATCH] fixed vector copy constructor bug --- include/blah/containers/vector.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/blah/containers/vector.h b/include/blah/containers/vector.h index b48f41e..5d706de 100644 --- a/include/blah/containers/vector.h +++ b/include/blah/containers/vector.h @@ -80,7 +80,7 @@ namespace Blah m_count = m_capacity = 0; reserve(src.m_capacity); for (int i = 0; i < src.m_count; i++) - m_buffer[i] = src.m_buffer[i]; + new (m_buffer + i) T(src.m_buffer[i]); m_count = src.m_count; } @@ -213,13 +213,17 @@ namespace Blah template inline void Vector::push_back(const T& item) { - emplace_back(item); + reserve(m_count + 1); + new (m_buffer + m_count) T(item); + m_count++; } template inline void Vector::push_back(T&& item) { - emplace_back(std::move(item)); + reserve(m_count + 1); + new (m_buffer + m_count) T(std::move(item)); + m_count++; } template