-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertInLoop.cpp
More file actions
47 lines (37 loc) · 935 Bytes
/
InsertInLoop.cpp
File metadata and controls
47 lines (37 loc) · 935 Bytes
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
/*
* \file InsertInLoop.cpp
* \brief Inserting into a list
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
struct Item
{
size_t id;
};
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::list<Item> items { {1}, {2}, {3}, {4}, {5} };
for (auto it = items.begin(); it != items.end(); ++ it) {
if (it->id == 3) {
items.insert(++ it, Item{777});
}
}
std::cout << "items:\n\n";
for (auto &it : items) {
std::cout << STD_TRACE_VAR(it.id) << std::endl;
}
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
items:
it.id: 1
it.id: 2
it.id: 3
it.id: 777
it.id: 4
it.id: 5
#endif