splicing the last element to the end drops it
Closed this issue · 3 comments
cscrimge commented
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
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
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
<#22 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABE4FIRNFPX6AHZQRH7FHIDVCOEJNANCNFSM5R75SVRA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
mattreecebentley commented
Fixed now - please double-check though