我想拼接范围[first, last],包括两个端点.我之前 first和之前都有元素的迭代器last.我能做到splice_after()但只能在线性时间内完成.
我相信这种拼接可以在恒定的时间内完成.我怎么能这样做std::forward_list?
如果问题不明确,这里显示我的问题的示例代码:
实时工作空间代码
#include <algorithm>
#include <forward_list>
#include <iostream>
#include <iterator>
using namespace std;
int main() {
forward_list<char> trg{'a','b','c'};
forward_list<char> src{'1','2','3','4'};
auto before_first = src.begin();
auto last = find(src.begin(), src.end(), '4');
cout << "before_first = " << *before_first << ", last = " << *last << "\n";
// trg.splice(trg.begin(), src, before_first, last); // no such splice
auto end = last;
++end; // Ouch! …Run Code Online (Sandbox Code Playgroud)