这很奇怪..以下代码(感谢Cassio Neri我设法编译)正在编译没有任何错误..顺便说一下 hashing_func 和 key_equal_func 确实被调用了(控制台窗口中没有显示 couts )
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <functional>
using namespace std;
unsigned long hashing_func(string key)
{
cout << "Hashing called";
unsigned long hash = 0;
for(int i=0; i<key.size(); i++)
{
hash += (71*hash + key[i]) % 5;
}
return hash;
}
template<class T> bool key_equal_fn(T t1, T t2)
{
return t1 == t2;
}
template <> bool key_equal_fn<string>(string t1, string t2)
{
cout << "Equal called";
return !(t1.compare(t2));
}
int main ()
{
unordered_map<string, string>::size_type n = 5;
unordered_map<string, string> mymap(n, (const std::hash<string> &)hashing_func,
(const std::equal_to<string> &)(function<bool(string,string)>(key_equal_fn<string>))) ;
bool case_insensitive = mymap.key_eq()("test","TEST");
mymap["paul"] = "jenna";
mymap["frank"] = "ashley";
if(mymap["paul"] == mymap["frank"])
cout << "equal" << endl;
return 0;
}
我正在使用 MSVC2012,有什么提示可能是什么问题吗?