code?
for(auto it = this->holder.end()-1;it >= this->holder.begin();--it){
if(*it == 0){
it = this->holder.erase(it);
}else{
break;
}
}
this->holder.shrink_to_fit();
it gets
double free or corruption (out)
Signal: SIGABRT (Aborted)
at line
this->holder.shrink_to_fit();
https://stackoverflow.com/help/minimal-reproducible-example What is type of the holder ? Why you are using raw-loop instead of std::remove + std::erase or at least Reverse Iterators? What do you want to do?
I got used reverse iterator that's not much different from normal iterator type of holder is std::vector<unsigned int> and I use vector::erase i don't think there would be and difference between the method and std::erase I want to erase all 0 element from the end-1(last element) to begin and stop deleting when I got any other value
Just use Reverse Iterators + std::remove + std::erase instead of those buggy loops. https://gist.githubusercontent.com/another-ghasem/565dfd86c6abaccd031e04be16963314/raw/5ef21487a63968e711d041d291a9cd7af8b8cec6/main.cc
but I don't want to erase 0s in middle nor in beginning
Обсуждают сегодня