Skip to content

Commit 9dd6c37

Browse files
AndrewDeanMSColin Robertson
authored andcommitted
Don't use undefined behavior for insert example (MicrosoftDocs#618)
Create a copy of the vector, so that first and last aren't iterators into the vector being inserted into. Remove the redefinition of Iter that is incorrect and caused compilation failure
1 parent fe34199 commit 9dd6c37

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/standard-library/vector-class.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,8 @@ int main( )
12081208
cout << " " << *Iter;
12091209
cout << endl;
12101210

1211-
v1.insert( v1.begin( )+1, v1.begin( )+2, v1.begin( )+4 );
1211+
const auto v2 = v1;
1212+
v1.insert( v1.begin( )+1, v2.begin( )+2, v2.begin( )+4 );
12121213
cout << "v1 =";
12131214
for (Iter = v1.begin( ); Iter != v1.end( ); Iter++ )
12141215
cout << " " << *Iter;
@@ -1220,7 +1221,6 @@ int main( )
12201221
vv1.insert( vv1.begin(), move( v1 ) );
12211222
if ( vv1.size( ) != 0 && vv1[0].size( ) != 0 )
12221223
{
1223-
vector < vector <int> >::iterator Iter;
12241224
cout << "vv1[0] =";
12251225
for (Iter = vv1[0].begin( ); Iter != vv1[0].end( ); Iter++ )
12261226
cout << " " << *Iter;

0 commit comments

Comments
 (0)