std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::erase
Min standard notice:
Removes specified elements from the container.
# Declarations
iterator erase( iterator position );
(since C++23)
iterator erase( const_iterator pos );
(since C++23)
iterator erase( const_iterator first, const_iterator last );
(since C++23)
size_type erase( const Key& key );
(since C++23)
template< class K >
size_type erase( K&& x );
(since C++23)
# Parameters
pos: iterator to the element to removefirst, last: range of elements to removekey: key value of the elements to removex: a value of any type that can be transparently compared with a key denoting the elements to remove
# Example
#include <flat_map>
#include <iostream>
int main()
{
std::flat_map<int, std::string> c =
{
{1, "one"}, {2, "two"}, {3, "three"},
{4, "four"}, {5, "five"}, {6, "six"}
};
// erase all odd numbers from c
for (auto it = c.begin(); it != c.end();)
{
if (it->first % 2 != 0)
it = c.erase(it);
else
++it;
}
for (auto& p : c)
std::cout << p.second << ' ';
std::cout << '\n';
}