I saw the following code used to remove one selected item from std::vector:
vector<hgCoord>::iterator it;
int iIndex = 0;
const int iSelected = 5;
for( it = vecPoints.begin(); it != vecPoints.end(); ++it, ++iIndex )
{
if( iIndex == iSelected )
{
vecPoints.erase( it );
break;
}
}
I maintain that this code is inefficient and should be written as follows:
vector<hgCoord>::iterator it;
int iIndex = 0;
const int iSelected = 5;
vecPoints.erase( vecPoints.begin() + iSelected );
However, I'm not sure if this code complies with the STL C ++ standard.
q0987 source
share