本文测试c++中基本类型的哈希值。
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "hash value = " << hash<int>()(123) << endl;
cout << "hash value = " << hash<long>()(123L) << endl;
cout << "hash value = " << hash<string>()("April") << endl;
cout << "hash value = " << hash<const char*>()("April") << endl;
cout << "hash value = " << hash<char>()('A') << endl;
cout << "hash value = " << hash<float>()(3.141592653) << endl;
cout << "hash value = " << hash<double>()(3.141592653) << endl;
}
执行结果
hash value = 123
hash value = 123
hash value = 11180089857043078576
hash value = 4197906
hash value = 65
hash value = 5571527677581354652
hash value = 14104971651001058672