- hash_map string key 忽略大小写。
- 转自网络,没有测试是否可用
- #include <hash_map>
- #include <string>
- #include <algorithm>
- #include <cctype>
- inline size_t __stl_hash_string(const char* __s)
- {
- unsigned long __h = 0;
- for ( ; *__s; ++__s)
- __h = 5*__h + tolower(*__s);
- return size_t(__h);
- }
- template<>
- struct stlport::hash<stlport::string>
- {
- size_t operator()(const stlport::string& __s) const
- {
- return __stl_hash_string(__s.c_str());
- }
- };
- template<>
- struct stlport::equal_to<stlport::string>
- : public stlport::binary_function<stlport::string , stlport::string , bool>
- {
- bool operator()(const stlport::string& __x, const stlport::string& __y) const
- {
- return !_stricmp(__x.c_str() , __y.c_str());
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- stlport::hash_map<stlport::string , int> map;
- map.insert(stlport::make_pair("Test" , 123));
- stlport::hash_map<stlport::string , int>::iterator iter = map.find("teSt");
- if(iter != map.end())
- printf("Found!\n");
- return 0;
- }
hash_map string key 忽略大小写
最新推荐文章于 2023-04-07 16:14:13 发布