mattreecebentley/plf_list

splicing the last element to the end drops it

Closed this issue · 3 comments

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;
}

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"

Fixed now - please double-check though