I want to use the new C++11 for each loop to iterate over all elements of a list and erase certains elements. For example
std::list<int> myList;
myList.push_back(1);
myList.push_back(13);
myList.push_back(9);
myList.push_back(4);
for(int element : myList) {
if(element > 5) {
//Do something with the element
//erase the element
}else{
//Do something else with the element
}
}
Is it possible to do this using the for each loop or do I have to go back to iterators to achive this?