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

missing splice interface #23

Closed gigglesun closed 2 years ago

gigglesun commented 2 years ago

plf::list do not have same splice interface as std::list as below

void  splice(const_iterator __position, list&& __x, const_iterator __first,  const_iterator __last) noexcept

following code can compile through, change to plf::list, will failed to compile

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

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

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

  std::list<int> list2 = { 11, 22, 33, 44, 55 };
  list1.splice(list1.end(), list2, list2.begin(), list2.end());

  print(list1);
  print(list2);

  return 0;
}
mattreecebentley commented 2 years ago

That's correct, an unrolled list cannot have that kind of functionality as it requires splitting blocks and thereby invalidating pointers to elements. From the plflib page: It's functionality replicates std::list with two minor exceptions: the removal of single-element and ranged splices when the source is not *this