hash_map string key 忽略大小写
来源:互联网 发布:ubuntu开机自启动程序 编辑:程序博客网 时间:2024/06/05 16:14
- hash_map string key 忽略大小写。
- 转自网络,没有测试是否可用
- #include <hash_map>
- #include <string>
- #include <algorithm>
- #include <cctype>
-
- inline size_t __stl_hash_string(constchar* __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>::iteratoriter = map.find("teSt");
- if(iter !=map.end())
- printf("Found!\n");
-
- return 0;
- }