std::flat_multiset<Key,Compare,KeyContainer>:: clear
From cppreference.net
<
cpp
|
container
|
flat multiset
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::flat_multiset
| Member types | ||||
| Member functions | ||||
| Non-member functions | ||||
| Helper classes | ||||
| Tags | ||||
| Deduction guides | ||||
|
void
clear
(
)
noexcept
;
|
(C++23 起)
(C++26 起为 constexpr) |
|
从容器的适配器中擦除所有元素。此调用后, size() 返回零。
使所有指向容器元素的引用、指针和迭代器失效。
复杂度
线性于容器适配器的大小,即元素的数量。
示例
运行此代码
#include <iostream> #include <string_view> #include <flat_set> void print_info(std::string_view rem, const std::flat_multiset<int>& v) { std::cout << rem << "{ "; for (const auto& value : v) std::cout << value << ' '; std::cout << "}\n"; std::cout << "Size=" << v.size() << '\n'; } int main() { std::flat_multiset<int> container{1, 2, 3}; print_info("Before clear: ", container); container.clear(); print_info("After clear: ", container); }
输出:
Before clear: { 1 2 3 }
Size=3
After clear: { }
Size=0
参见
|
擦除元素
(公开成员函数) |