i have an array arr of vectors and I want to search and remove from the array vectors which have a specific value in one of elements, call it elementA. It happens to me, that if you have a look inside the array, such condition is fullfilled for a couple of consecutive vectors in a row.
In your code:
int eStart = -1; int eEnd = -1;
for ( int i=0; i<arr.size()-1; i++ )
{
if ( -1 == eStart && arr[i].getElementA() == 0 )
eStart = i;
if ( arr[i].getElementA() == 0 )
eEnd = i;
}
arr.erase( arr.begin()+eStart, arr.begin()+eEnd );
The second iterator passed to erase have to be One past the last you want to erase (and call erase only if you finded some element that need to be erase):
arr.erase( arr.begin()+eStart, arr.begin()+eEnd +1 );
The error: checking the "range of iterators" during arithmetic’s: the result have to be >=
the first element, and <=
the last element. begin()-1
don't fit: that is what you have when you don’t check if finded, that is when eRtart=-1
.
_SCL_SECURE_VALIDATE_RANGE(
_Myptr + _Off <= ((_Myvec *)(this->_Getmycont()))->_Mylast &&
_Myptr + _Off >= ((_Myvec *)(this->_Getmycont()))->_Myfirst);
_Myptr += _Off;
NOTE: It is not recomended to inherit from std::containers.