-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEraseRemove.cpp
More file actions
52 lines (40 loc) · 1.03 KB
/
EraseRemove.cpp
File metadata and controls
52 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* \file EraseRemove.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::vector<int> vec {10,20,30,30,20,10,10,20}; // 10 20 30 30 20 10 10 20
// remove
auto itEnd = std::remove(vec.begin(), vec.end(), 20); // 10 30 30 10 10 ? ? ?
std::cout << "[remove it]:";
for (auto it = vec.begin(); it != itEnd; ++ it) {
std::cout << ' ' << *it;
}
std::cout << '\n';
std::cout << "[remove]: ";
for (auto &it : vec) {
std::cout << ' ' << it;
}
std::cout << '\n';
// erase
vec.erase(itEnd, vec.end());
std::cout << "[erase]: ";
for (auto &it : vec) {
std::cout << ' ' << it;
}
std::cout << '\n';
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
[remove it]: 10 30 30 10 10
[remove]: 10 30 30 10 10 10 10 20
[erase]: 10 30 30 10 10
#endif