Skip to content

Commit

Permalink
C++20 コンテナの非メンバ関数erase/erase_if : 戻り値改善の仕様変更を適用
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed Nov 11, 2020
1 parent 31fb83b commit 4940a03
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 40 deletions.
9 changes: 7 additions & 2 deletions reference/deque/deque/erase_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ namespace std {
以下と等価:
```
c.erase(remove(c.begin(), c.end(), value), c.end());
auto it = remove(c.begin(), c.end(), value);
auto r = distance(it, c.end());
c.erase(it, c.end());
return r;
```
* c.erase[link erase.md]
* remove[link /reference/algorithm/remove.md]
* distance[link /reference/iterator/distance.md]
* c.begin()[link begin.md]
* c.end()[link end.md]
Expand Down Expand Up @@ -68,4 +72,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
9 changes: 7 additions & 2 deletions reference/deque/deque/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ namespace std {
以下と等価:
```
c.erase(remove_if(c.begin(), c.end(), pred), c.end());
auto it = remove_if(c.begin(), c.end(), pred);
auto r = distance(it, c.end());
c.erase(it, c.end());
return r;
```
* c.erase[link erase.md]
* remove_if[link /reference/algorithm/remove_if.md]
* distance[link /reference/iterator/distance.md]
* c.begin()[link begin.md]
* c.end()[link end.md]
Expand Down Expand Up @@ -68,4 +72,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
3 changes: 2 additions & 1 deletion reference/forward_list/forward_list/erase_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
3 changes: 2 additions & 1 deletion reference/forward_list/forward_list/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
3 changes: 2 additions & 1 deletion reference/list/list/erase_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
3 changes: 2 additions & 1 deletion reference/list/list/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/map/map/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class Key, class T, class Compare, class Allocator, class Predicate>
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);
typename map<Key, T, Compare, Allocator>::size_type
erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);
}
```
Expand All @@ -21,21 +22,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -78,4 +82,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/map/multimap/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class Key, class T, class Compare, class Allocator, class Predicate>
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
typename multimap<Key, T, Compare, Allocator>::size_type
erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
}
```
Expand All @@ -21,21 +22,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -78,4 +82,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/set/multiset/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class Key, class Compare, class Allocator, class Predicate>
void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);
typename multiset<Key, Compare, Allocator>::size_type
erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);
}
```
Expand All @@ -19,21 +20,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -72,4 +76,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/set/set/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class Key, class Compare, class Allocator, class Predicate>
void erase_if(set<Key, Compare, Allocator>& c, Predicate pred);
typename set<Key, Compare, Allocator>::size_type
erase_if(set<Key, Compare, Allocator>& c, Predicate pred);
}
```
Expand All @@ -19,21 +20,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -72,4 +76,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
9 changes: 7 additions & 2 deletions reference/string/basic_string/erase_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ namespace std {
以下と等価:
```
c.erase(remove(c.begin(), c.end(), value), c.end());
auto it = remove(c.begin(), c.end(), value);
auto r = distance(it, c.end());
c.erase(it, c.end());
return r;
```
* c.erase[link erase.md]
* remove[link /reference/algorithm/remove.md]
* distance[link /reference/iterator/distance.md]
* c.begin()[link begin.md]
* c.end()[link end.md]
Expand Down Expand Up @@ -64,4 +68,5 @@ HelloWorld


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
9 changes: 7 additions & 2 deletions reference/string/basic_string/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ namespace std {
以下と等価:
```
c.erase(remove_if(c.begin(), c.end(), pred), c.end());
auto it = remove_if(c.begin(), c.end(), pred);
auto r = distance(it, c.end());
c.erase(it, c.end());
return r;
```
* c.erase[link erase.md]
* remove_if[link /reference/algorithm/remove_if.md]
* distance[link /reference/iterator/distance.md]
* c.begin()[link begin.md]
* c.end()[link end.md]
Expand Down Expand Up @@ -64,4 +68,5 @@ HelloWorld


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/unordered_map/unordered_map/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class K, class T, class H, class P, class A, class Predicate>
void erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred);
typename unordered_map<K, T, H, P, A>::size_type
erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred);
}
```
Expand All @@ -21,21 +22,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -78,4 +82,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
11 changes: 8 additions & 3 deletions reference/unordered_map/unordered_multimap/erase_if_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
```cpp
namespace std {
template <class K, class T, class H, class P, class A, class Predicate>
void erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred);
typename unordered_multimap<K, T, H, P, A>::size_type
erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred);
}
```
Expand All @@ -21,21 +22,24 @@ namespace std {
以下と等価:
```
auto original_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
return original_size - c.size();
```
* c.begin()[link begin.md]
* c.end()[link end.md]
* c.erase[link erase.md]
* c.size()[link size.md]
## 戻り値
なし
削除した要素数を返す。
## 例
Expand Down Expand Up @@ -79,4 +83,5 @@ int main()


## 参照
- [P1209R0 | Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [P1209R0 Adopt consistent container erasure from Library Fundamentals 2](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html)
- [R1115R3 Improving the Return Value of Erase-Like Algorithms II: Free `erase`/`erase_if`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1115r3.pdf)
Loading

0 comments on commit 4940a03

Please sign in to comment.