I am trying out the stl concepts and started facing the segmentation fault when using remove_if of list.
Following is the code I was trying. i am not compeletely sure if the usage of remove_if is done correctly.
Please help me in understandin what is wrong with the code and also if the usage of remove_if is correct.(i see many using operator() for remove_if but i dont understand why)
I believe the problem is that you're modifying(deleting items) the container in your loop, which invalidates the iterator. Basically once you call remove_if, i is no longer valid and can't be used unless it's reset.
Anyway you don't need to loop. remove_if will remove all elements that match your predicate.