命名空间
变体
操作

std::flat_multiset<Key,Compare,KeyContainer>::clear

来自 cppreference.cn
 
 
 
 
void clear() noexcept;
(自 C++23 起)

从容器适配器中移除所有元素。在此调用后,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

[编辑] 参见

移除元素
(公共成员函数) [编辑]