template <class T> struct hash; |
头文件 | 类型 |
<functional> | bool char signed char unsigned char char16_t char32_t wchar_t short unsigned short int unsigned int long unsigned long long long unsigned long long float double long double T* (for any type T) |
<string> | string wstring u16string u32string |
<memory> | unique_ptr shared_ptr |
<vector> | vector<bool> |
<bitset> | bitset |
<system_error> | error_code |
<typeindex> | type_index |
<thread> | thread::id |
成员类型 | 定义 | 注释 |
result_type | size_t | 生成的哈希值的类型。 |
argument_type | T | 作为参数的值的类型。 |
// hash example #include <iostream> #include <functional> #include <string> int main () { char nts1[] = "Test"; char nts2[] = "Test"; std::string str1 (nts1); std::string str2 (nts2); std::hash<char*> ptr_hash; std::hash<std::string> str_hash; std::cout << "same hashes:\n" << std::boolalpha; std::cout << "nts1 and nts2: " << (ptr_hash(nts1)==ptr_hash(nts2)) << '\n'; std::cout << "str1 and str2: " << (str_hash(str1)==str_hash(str2)) << '\n'; return 0; } |