From aba90ba5314d980b9e8cc9c25854c4a93ff88152 Mon Sep 17 00:00:00 2001 From: psiha Date: Tue, 17 Sep 2024 15:11:19 +0200 Subject: [PATCH] Fixed a bug in the 'trivial' version of vector<>::make_space_for_insert(). --- include/psi/vm/vector.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/psi/vm/vector.hpp b/include/psi/vm/vector.hpp index 84e72b5..20b2301 100644 --- a/include/psi/vm/vector.hpp +++ b/include/psi/vm/vector.hpp @@ -1185,13 +1185,13 @@ class vector auto const current_size { size() }; auto const new_size { current_size + n }; storage_.expand( to_byte_sz( new_size ) ); + auto const elements_to_move{ static_cast( current_size - position_index ) }; if constexpr ( is_trivially_moveable ) { - std::move( nth( position_index ), nth( position_index + n ), nth( position_index + n ) ); + std::move( nth( position_index ), nth( position_index + elements_to_move ), nth( position_index + n ) ); } else // future support for generic types { - auto const elements_to_move { static_cast( current_size - position_index ) }; auto const elements_to_move_to_uninitialized_space{ n }; auto const elements_to_move_to_the_current_end { static_cast( elements_to_move - elements_to_move_to_uninitialized_space ) }; std::uninitialized_move_n( nth( current_size - elements_to_move_to_uninitialized_space ), elements_to_move_to_uninitialized_space, nth( current_size ) );