-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErase.cpp
45 lines (34 loc) · 1.32 KB
/
Erase.cpp
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
/**
* \file Erase.cpp
* \brief Removes from the list container either a single element (position) or a range of elements ([first,last)).
*
* This effectively reduces the container size by the number of elements removed, which are destroyed.
*
* Unlike other standard sequence containers, list and forward_list objects are specifically
* designed to be efficient inserting and removing elements in any position,
* even in the middle of the sequence.
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::list<int> items( {0, 1, 2, 3, 4, 5} );
std::cout << STD_TRACE_VAR(items) << std::endl;
std::list<int>::iterator it_item = ++ (items.begin());
// Erase #1
it_item = items.erase(it_item);
std::cout << "Erase #1: " << STD_TRACE_VAR(items) << std::endl;
// Erase #2
++ it_item;
items.erase(it_item, items.end());
std::cout << "Erase #2: " << STD_TRACE_VAR(items) << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
items: std::list (size=6): {0,1,2,3,4,5}
Erase #1: items: std::list (size=5): {0,2,3,4,5}
Erase #2: items: std::list (size=2): {0,2}
#endif