Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d210ea7
commit 7f2cc9c
Showing
4 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# erase_if | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
template<class Key, | ||
class T, | ||
class Compare, | ||
class KeyContainer, | ||
class MappedContainer, | ||
class Predicate> | ||
typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type | ||
erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, | ||
Predicate pred); | ||
} | ||
``` | ||
## 概要 | ||
指定した条件に合致する要素とその分の領域を、コンテナから削除する。 | ||
述語関数オブジェクトには、キーではなく、要素全体 (キーと値の[`pair`](/reference/utility/pair.md)) が渡されるので注意。 | ||
## 事前条件 | ||
- `Key`と`T`がムーブ代入可能であること | ||
## 効果 | ||
メンバ変数として保持しているコンテナ`c`の各要素`e`について、`bool(pred(pair<const Key&, const T&>(e)))`を`E`として、`E`が`true`であるすべての要素を削除する。 | ||
## 戻り値 | ||
削除した要素数を返す。 | ||
## 計算量 | ||
正確に[`size()`](size.md)回だけ述語適用する。 | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <flat_map> | ||
int main() | ||
{ | ||
std::flat_map<int, char> fm = { | ||
{3, 'a'}, | ||
{1, 'b'}, | ||
{4, 'c'} | ||
}; | ||
// コンテナfmから、キー1をもつ要素をすべて削除する | ||
std::erase_if(fm, [](const auto& x) { return x.first == 1; }); | ||
for (const auto& [key, value] : fm) { | ||
std::cout << key << ':' << value << std::endl; | ||
} | ||
} | ||
``` | ||
* std::erase_if[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
3:a | ||
4:c | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters