[flat.map.erasure]

# 23 Containers library [[containers]](./#containers)

## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.erasure)

### 23.6.8 Class template flat_map [[flat.map]](flat.map#erasure)

#### 23.6.8.8 Erasure [flat.map.erasure]

[ð](#lib:erase_if,flat_map)

`template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
         class Predicate>
  constexpr typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type
    erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18116)

*Preconditions*: Key and T meet the *Cpp17MoveAssignable* requirements[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18120)

*Effects*: Let E be bool(pred(pair<const Key&, const T&>(e)))[.](#2.sentence-1)

Erases all elements e in c for which E holds[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18125)

*Returns*: The number of elements erased[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18129)

*Complexity*: Exactly c.size() applications of the predicate[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18133)

*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8 Requirements for stable algorithms"))[.](#5.sentence-1)

If an invocation of erase_if exits via an exception,c is in a valid but unspecified state ([[defns.valid]](defns.valid "3.67 valid but unspecified state"))[.](#5.sentence-2)

[*Note [1](#note-1)*:

c still meets its invariants,
but can be empty[.](#5.sentence-3)

â *end note*]
