I want to call the find function on a vector of pairs. At the time the find function is called I only have the key to search by.
My understanding is that I need to pass a function into find as an argument to do the comparison for me but I can't find a proper example.
The reason I'm sorting the pairs within a vector opposed to a map container is because I want to be able to sort the pairs by value after the population process.
vector< pair<string, int> > sortList;
vector< pair<string, int> >::iterator it;
for(int i=0; i < Users.size(); i++)
{
it = find( sortList.begin(), sortList.end(), findVal(Users.userName) );
//Item exists in map
if( it != sortList.end())
{
//increment key in map
it->second++;
}
//Item does not exist
else
{
//Not found, insert in map
sortList.push_back( pair<string,int>(Users.userName, 1) );
}
}
//Sort the list
//Output
The implementation on findVal
is the fuzzy area for me. I'd also be open to better ways of implementing the logic.