當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Forward_list splice_after()用法及代碼示例


描述

C++ 函數std::forward_list::splice_after()從 forward_list 傳輸所有元素x*這個位置.容器x操作後變為空。

聲明

以下是 std::forward_list::splice_after() 函數形式 std::forward_list 頭文件的聲明。

C++11

void splice_after (const_iterator position, forward_list& x);

參數

  • position- 在 forward_list 中插入新元素後的位置。

  • x− 另一個相同類型的 forward_list 對象。

返回值

異常

此成員函數從不拋出異常。

時間複雜度

線性,即 O(n)

示例

下麵的例子展示了 std::forward_list::splice_after() 函數的用法。

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

   forward_list<int> fl1 = {2, 3, 4};
   forward_list<int> fl2 = {1, 5};

   fl2.splice_after(fl2.begin(), fl1);

   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

相關用法


注:本文由純淨天空篩選整理自 C++ Forward_list Library - splice_after() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。