最終更新日時(UTC):
が更新

履歴 編集

function
<forward_list>

std::forward_list::splice_after(C++11)

void splice_after(const_iterator position, forward_list& x);  // (1)
void splice_after(const_iterator position, forward_list&& x); // (2)

void splice_after(const_iterator position, forward_list& x,
                  const_iterator i);                          // (3)

void splice_after(const_iterator position, forward_list&& x,
                  const_iterator i);                          // (4)

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

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

概要

他のコンテナから要素を移動する。

要件

効果

  • (1),(2) : positionの指す要素の後ろに、xの全ての要素を移動する
  • (3),(4) : positionの指す要素の後ろに、xの要素のうちiの次の要素を移動する
  • (5),(6) : positionの指す要素の後ろに、xの要素のうち(first, last)の範囲を移動する

戻り値

なし

例外

  • (1) : 投げない
  • (2) : 投げない
  • (3) : 投げない
  • (4) : 投げない

計算量

  • (1), (2) : xの要素数に対して線形時間
  • (3), (4) : 定数時間
  • (5), (6) : (first, last)の要素数に対して線形時間

備考

  • (1), (2) : この関数を呼び出したあとも、xの各要素へのポインタ、参照、イテレータは有効である。ただし、そのポインタと参照は、xではなく*thisの要素となる。
  • (3), (4) : この関数を呼び出したあとも、*++iへのポインタ、参照、イテレータは有効である。ただし、そのポインタと参照は、xではなく*thisの要素となる。
  • (5), (6) : この関数を呼び出したあとも、(first, last)の各要素へのポインタ、参照、イテレータは有効である。ただし、そのポインタと参照は、xではなく*thisの要素となる。

#include <iostream>
#include <forward_list>
#include <utility>
#include <iterator>

template <class T>
void print(const std::forward_list<T>& ls)
{
  for (const T& x : ls) { std::cout << x << ' '; }
  std::cout << std::endl;
}

int main()
{
  // ysの全ての要素をxsに移動する
  {
    std::forward_list<int> xs = {1, 5, 6};
    std::forward_list<int> ys = {2, 3, 4};

    xs.splice_after(xs.begin(), std::move(ys));

    print(xs);
  }
  // ysのうち、3だけを移動する
  {
    std::forward_list<int> xs = {1, 5, 6};
    std::forward_list<int> ys = {2, 3, 4};

    xs.splice_after(xs.begin(), std::move(ys), ys.begin());

    print(xs);
  }
  // ysのうち、2と3だけを移動する
  {
    std::forward_list<int> xs = {1, 5, 6};
    std::forward_list<int> ys = {2, 3, 4};

    xs.splice_after(xs.begin(), std::move(ys), ys.before_begin(), std::next(ys.begin(), 2));

    print(xs);
  }
}

出力

1 2 3 4 5 6 
1 3 5 6 
1 2 3 5 6 

バージョン

言語

  • C++11

処理系

参照