diff --git a/include/psi/vm/vector.hpp b/include/psi/vm/vector.hpp index 0f70b4b..84e72b5 100644 --- a/include/psi/vm/vector.hpp +++ b/include/psi/vm/vector.hpp @@ -1178,15 +1178,25 @@ class vector iterator make_space_for_insert( const_iterator const position, size_type const n ) { + using ssize_type = std::make_signed_t; + verify_iterator( position ); auto const position_index{ index_of( position ) }; auto const current_size { size() }; auto const new_size { current_size + n }; storage_.expand( to_byte_sz( new_size ) ); - auto const elements_to_move_uninitialized_space{ static_cast( current_size - position_index ) }; - auto const elements_to_move_to_the_current_end { static_cast( n - elements_to_move_uninitialized_space ) }; - std::uninitialized_move_n( nth( current_size - elements_to_move_uninitialized_space ), elements_to_move_uninitialized_space , nth( static_cast( new_size - elements_to_move_uninitialized_space ) ) ); - std::move ( nth( position_index ), nth( position_index + elements_to_move_to_the_current_end ), nth( static_cast( new_size - n ) ) ); + if constexpr ( is_trivially_moveable ) + { + std::move( nth( position_index ), nth( position_index + n ), 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 ) ); + std::move ( nth( position_index ), nth( position_index + elements_to_move_to_the_current_end ) , nth( position_index + n ) ); + } return nth( position_index ); } }; // class vector