First I will give a specific case, and the I would like to see if it can be applied to a general problem.
Say I have map. And I want to get all the keys meeting a certain criteria. For example all keys that contain "COL". My naive implementation will be
template<typename T>
void Filter (map<string, T> & m, std:set<string> & result, const std::string& condition)
{
for(map<string,string> iter=m.begin();iter!m.end();iter++)
{
std::string key=iter->first;
size_t found=key.find(condition);
if (found!=string::npos)
result.insert(key);
}
}
what is the good way to implement this?
Also, what is a good way to implement general problem when I want to filter map using algos?