I want to use specified equal_to function int unordered_set The sample code likes this:
struct myEqual
{ //string with one different character is considered equal
bool operator()(const string &s1, const string &s2)const
{
if(s1.length() != s2.length()) return false;
int dis = 0;
for(unsigned int i = 0; i<s1.size(); i++)
{
if(s1[i] != s2[i])
{
dis++;
if(dis >= 2) return false;
}
}
return true;
}
};
int main()
{
unordered_set<string, std::tr1::hash<string>, myEqual> myDict;
myDict.insert("a");
myDict.insert("b");
myDict.insert("c");
unordered_set<string, std::tr1::hash<string>, myEqual>::iterator it = myDict.find("k");
if(it == myDict.end())
{
cout<<"myequal not work"<<endl;
}
else
{
cout<<*it<<endl;
}
return 0;
}
according to myEqual function, there are three values "a", "b", "c" that are "equal" to "k", however the find only return one iterator. Is there anyway to find all equal value?