std::forward_list<T,Allocator>:: clear
From cppreference.net
<
cpp
|
container
|
forward list
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::forward_list
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
void
clear
(
)
noexcept
;
|
(C++11以降)
(constexpr C++26以降) |
|
コンテナからすべての要素を削除します。
格納されている要素を参照するすべての参照、ポインタ、およびイテレータは無効になります。 past-the-endイテレータは有効なままです。
目次 |
計算量
コンテナのサイズ、すなわち要素数に対して線形。
例
このコードを実行
#include <iostream> #include <string_view> #include <forward_list> void print_info(std::string_view rem, const std::forward_list<int>& v) { std::cout << rem << "{ "; for (const auto& value : v) std::cout << value << ' '; std::cout << "}\n"; } int main() { std::forward_list<int> container{1, 2, 3}; print_info("Before clear: ", container); container.clear(); print_info("After clear: ", container); }
出力:
Before clear: { 1 2 3 }
After clear: { }
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2231 | C++11 | 計算量保証がC++11で誤って省略されていた | 計算量が線形であることを再確認 |
関連項目
|
要素の後の要素を削除する
(公開メンバ関数) |