std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::clear
來自 cppreference.com
void clear() noexcept; |
(C++23 起) | |
從容器介面卡中擦除所有元素。此呼叫後,size() 返回零。
使所有引用、指標和指向所含元素的迭代器失效。
[edit] 複雜度
與容器介面卡的大小(即元素數量)呈線性關係。
[edit] 示例
執行此程式碼
#include <iostream> #include <string_view> #include <flat_map> void print_info(std::string_view rem, const std::flat_map<int, char>& v) { std::cout << rem << "{ "; for (const auto& [key, value] : v) std::cout << '[' << key << "]:" << value << ' '; std::cout << "}\n"; std::cout << "Size=" << v.size() << '\n'; } int main() { std::flat_map<int, char> container{{1, 'x'}, {2, 'y'}, {3, 'z'}}; print_info("Before clear: ", container); container.clear(); print_info("After clear: ", container); }
輸出
Before clear: { [1]:x [2]:y [3]:z } Size=3 After clear: { } Size=0
[edit] 參閱
擦除元素 (public member function) |