mattreecebentley / plf_list

A drop-in replacement for std::list with 293% faster insertion, 57% faster erasure, 17% faster iteration and 77% faster sorting on average. 20-24% speed increase in use-case testing.
https://plflib.org/list.htm
zlib License
151 stars 21 forks source link

splicing the last element to the end drops it #22

Closed cscrimge closed 2 years ago

cscrimge commented 2 years ago

Calling splice() to move the last element to the end drops it

#include <iostream>
#include "plf_list.h"

void print(const plf::list<int>& list1)
{
  for (auto& elem : list1)
  {
    std::cout << elem << ' ';
  }
  std::cout << std::endl;
}

int main()
{
  plf::list<int> list1 = { 1, 2, 3, 4, 5 };

  // Outputs "1 2 3 4 5 "
  print(list1);

  // This *should* be a no-op:
  list1.splice(list1.end(), std::prev(list1.end()));

  // Outputs "1 2 3 4"
  print(list1);

  return 0;
}
cscrimge commented 2 years ago

Update: Similarly, splicing to the beginning has the same issue. If you replace the splice() call above with

list1.splice(list1.begin(), list1.begin());

Then the list ends up being: "2 3 4 5"

mattreecebentley commented 2 years ago

Thanks, will fix-

On Wed, 30 Mar 2022 at 12:07, Chris Scrimgeour @.***> wrote:

Update: Similarly, splicing to the beginning has the same issue. If you replace the splice() call above with

list1.splice(list1.begin(), list1.begin());

Then the list ends up being: "2 3 4 5"

— Reply to this email directly, view it on GitHub https://github.com/mattreecebentley/plf_list/issues/22#issuecomment-1082454303, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABE4FIRNFPX6AHZQRH7FHIDVCOEJNANCNFSM5R75SVRA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mattreecebentley commented 2 years ago

Fixed now - please double-check though