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

履歴 編集

function
<forward_list>

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

iterator before_begin() noexcept;
const_iterator before_begin() const noexcept;

概要

先頭要素の前を指すイテレータを取得する。

この関数は、insert_after()メンバ関数で先頭に要素を挿入するために使用できる。

戻り値

先頭要素の前を指すイテレータを返す。

例外

投げない

備考

この関数によって返されるイテレータは、以下の特徴を持つ:

  • 間接参照できない
  • インクリメントするとbegin()と等値になる
  • end()と等値にはならない

#include <iostream>
#include <forward_list>
#include <algorithm>

int main()
{
  std::forward_list<int> ls;

  ls.push_front(3);
  ls.insert_after(ls.before_begin(), 1); // 先頭に挿入

  std::for_each(ls.cbegin(), ls.cend(), [](int x) {
    std::cout << x << std::endl;
  });
}

出力

1
3

バージョン

言語

  • C++11

処理系

参照