Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 1.83 KB

File metadata and controls

78 lines (56 loc) · 1.83 KB

clear

  • forward_list[meta header]
  • std[meta namespace]
  • forward_list[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
void clear() noexcept;           // (1) C++11
constexpr void clear() noexcept; // (1) C++26

概要

全ての要素を削除する

効果

forward_listオブジェクトが管理しているすべての要素を破棄する。

また、要素を指す全ての参照、ポインタ、イテレータが無効になる。past-the-end イテレータは無効にならない。

戻り値

なし

例外

投げない

計算量

線形時間。全ての要素に対してデストラクタを呼び出す。

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

int main()
{
  std::forward_list<int> ls = {1, 2, 3};

  ls.clear();

  assert(ls.empty());

  std::for_each(ls.begin(), ls.end(), [](int x) {
    std::cout << x << std::endl;
  });
}
  • clear()[color ff0000]
  • ls.empty()[link empty.md]
  • ls.begin()[link begin.md]
  • ls.end()[link end.md]

出力

バージョン

言語

  • C++11

処理系

参照