读书人

HASH MAP支持哪些默许类型作为KEY?

发布时间: 2013-11-29 00:21:24 作者: rapoo

HASH MAP支持哪些默认类型作为KEY??
LINUX版本和WINDOWS版本的。

LINUX平台是G++4.2

[解决办法]
支持<操作符的都可以,虽然有的不是你想要的,比如字符串
[解决办法]

引用:
支持<操作符的都可以,虽然有的不是你想要的,比如字符串


从“HASH MAP”这个名字来看,好像不是这样的。
[解决办法]
随便搜了下标准
template <> struct hash<bool>;
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
template <> struct hash<char16_t>;
template <> struct hash<char32_t>;
template <> struct hash<wchar_t>;
template <> struct hash<short>;
template <> struct hash<unsigned short>;
template <> struct hash<int>;
template <> struct hash<unsigned int>;
template <> struct hash<long>;
template <> struct hash<long long>;
template <> struct hash<unsigned long>;
template <> struct hash<unsigned long long>;
template <> struct hash<float>;
template <> struct hash<double>;
template <> struct hash<long double>;
template<class T> struct hash<T*>;
template <size_t N> struct hash<bitset<N> >;
template <> struct hash<string>;
template <> struct hash<u16string>;
template <> struct hash<u32string>;
template <> struct hash<wstring>;
template <class Allocator> struct hash<vector<bool, Allocator> >;
[解决办法]
hash是需要=操作符,map是需要<
[解决办法]
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xhash
     28: // TEMPLATE FUNCTION hash_value
32: size_t hash_value(const _Kty& _Keyval)
50: size_t hash_value(const basic_string<_Elem, _Traits, _Alloc>& _Str)
57: inline size_t hash_value(_In_z_ const char *_Str)
62: inline size_t hash_value(_In_z_ const wchar_t *_Str)
68: inline size_t hash_value(_In_z_ const unsigned short *_Str)
101: long _Quot = (long)(hash_value(_Keyval) & LONG_MAX);
121: using stdext::hash_value;

[解决办法]
基本类型因为可以转换为整数,全都可以。
然后,字符串因为非常常用,也可以。
[解决办法]
支持提供散列函数和相等比较的所有类型
[解决办法]
基础的类型和结构,结构需要你重载<

读书人网 >C++

热点推荐