Fix potential self-move points

This commit is contained in:
Ion Gaztañaga
2022-08-21 02:19:44 +02:00
parent 19bb08cf17
commit 3a4cf45106
2 changed files with 6 additions and 3 deletions

View File

@ -175,7 +175,8 @@ void swap_and_update_key
{
if(begin != with){
::boost::adl_move_swap_ranges(begin, end, with);
::boost::adl_move_swap(*key_next, *key_range2);
if(key_next != key_range2) //Avoid potential self-swapping
::boost::adl_move_swap(*key_next, *key_range2);
if(key_next == key_mid){
key_mid = key_range2;
}
@ -217,7 +218,8 @@ RandIt2 buffer_and_update_key
while(begin != end) {
op(three_way_t(), begin++, with++, buffer++);
}
::boost::adl_move_swap(*key_next, *key_range2);
if (key_next != key_range2) //Avoid potential self-swapping
::boost::adl_move_swap(*key_next, *key_range2);
if (key_next == key_mid) {
key_mid = key_range2;
}

View File

@ -192,7 +192,8 @@ namespace pdqsort_detail {
// Put the pivot in the right place.
Iter pivot_pos = first - 1;
*begin = boost::move(*pivot_pos);
if(begin != pivot_pos) //Avoid potential self-move
*begin = boost::move(*pivot_pos);
*pivot_pos = boost::move(pivot);
return pdqsort_detail::pair<Iter, bool>(pivot_pos, already_partitioned);