目录

forward_list::splice

描述 (Description)

C ++函数std::forward_list::splice_after()通过使用移动语义来传输从x*第一个最后一个范围内的元素。 在元素指向的位置之后插入元素。

声明 (Declaration)

以下是std :: forward_list :: splice_after()函数形式std :: forward_list头的声明。

C++11

void splice_after (const_iterator position, forward_list&& x,
                   const_iterator first, const_iterator last);

参数 (Parameters)

  • position - 在forward_list中的位置,之后要插入新元素。

  • x - 相同类型的另一个forward_list对象。

  • first - 将迭代器输入到范围内的初始位置。

  • last - 将迭代器输入到范围内的最终位置。

返回值

没有

异常 (Exceptions)

该成员函数从不抛出异常。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: forward_list :: splice_after()函数的用法。

#include <iostream>
#include <forward_list>
using namespace std;
int main(void) {
   forward_list<int> fl1 = {1, 2, 3, 4};
   forward_list<int> fl2 = {1, 5};
   fl2.splice_after(fl2.begin(), move(fl1), fl1.begin(), fl1.end());
   cout << "List contains following elements" << endl;
   for (auto it = fl2.begin(); it != fl2.end(); ++it)
      cout << *it << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

List contains following elements
1
2
3
4
5
↑回到顶部↑
WIKI教程 @2018