I spent the past hour reading up on how to use the remove_if() function on the list and forward_list containers. However, I'm having trouble translating their properties to lists of objects. I have a larger existing project that I think would be much more efficient if I use the remove_if() function instead of my existing code.
I came up with pretty basic example to ask my question so I can translate the same concept to my larger project. I have a class called Reservation, for the example we'll say Reservation has two instance variables of type string called date and name. I built some accessor functions to get the values of those variables to use throughout my program. Now my question is, how do I use remove_if() to remove objects based on the values of their instance variables? I wrote what I thought was a valid expression in line 35 of the sample code below, but I'm having trouble referencing the private 'date' member of each object. I thought the keyword 'this' would work because remove_if() removes all elements in the container if the condition is true. In my scenario each element is an object so I need to be able to access the instance variables of each object. Would I maybe need to use an iterator instead?
So again, my question is, how can I remove objects based off of conditions from their instance variables? If I had 1000 Reservation objects in a foward_list, how could I remove all of the instances from the list where the private variable date equals "Monday"?