FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp_tests/t21_vector_list_iterator_stability.cpp at master · s-kramer/cpp_tests · GitHub
s-kramer
/
cpp_tests
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp_tests
/
t21_vector_list_iterator_stability.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (25 loc) · 978 Bytes
Breadcrumbs
cpp_tests
/
t21_vector_list_iterator_stability.cpp
Copy path
File metadata and controls
31 lines (25 loc) · 978 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
#
include
<
vector
>
#
include
<
list
>
/*
Note: Always prefer vector to list, unless you have other pointers you need to keep valid at the time of insertion\removal.
* (skramer, Mon 24 Mar 2014 09:19:39 AM CET)
*/
int
main
()
{
std::vector<
int
> v = {
1
,
2
,
3
,
4
,
5
,
6
};
auto
it= v.
begin
() +
2
;
std::cout <<
"
Vector iterator before deletion:
"
<< *it <<
'
\n
'
;
v.
erase
(v.
begin
() +
1
);
std::cout <<
"
Vector iterator after deletion:
"
<< *it <<
'
\n
'
;
std::list<
int
> mylist = {
1
,
2
,
3
,
4
,
5
,
6
};
std::list<
int
>::iterator lit1, lit2;
lit1 = lit2 = mylist.
begin
();
advance
(lit1,
1
);
advance
(lit2,
2
);
std::cout <<
"
List iterator 1 before deletion:
"
<< *lit1 <<
'
\n
'
;
std::cout <<
"
List iterator 2 before deletion:
"
<< *lit2 <<
'
\n
'
;
mylist.
erase
(lit1);
std::cout <<
"
List iterator 1 after deletion:
"
<< *lit1 <<
'
\n
'
;
std::cout <<
"
List iterator 2 after deletion:
"
<< *lit2 <<
'
\n
'
;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL