I am trying to use std::find_if to find an object that matches some criteria. Consider the following:
struct MyStruct { MyStruct(const int & id) : m_id(id) {} int m_id; }; ... std::vector<MyStruct> myVector; //... assume it contains things MyStruct toFind(1); std::vector<MyStruct>::iterator i = std::find_if(myVector.begin(), myVector.end(), ???); I am not sure what to put in the ???
All the examples I have seen have a lambda that uses a hard-coded value to check for the ID. What I want is to return the iterator/success only if the id of toFind matches the id of one of the items in the vector.
All the examples I have see don't show me how to pass the two parameters
EDIT
Additional info There are two different scenarios I have to use this for One in which there is an == operator for the struct and another in which there is no operator == for the struct - and i can't create one because the criteria for finding a match for this scenario is not as rigid as would be used for an equivalence operator.
(And thanks to all who responded; I was able to use find() in one case and with your help was able to use find_if() for the other)