I'm trying to create following unordered_map:
std::unordered_map<CString, CString, std::function<size_t(const CString &data)>> usetResponse(100, [](const CString &data)
{
return std::hash<std::string>()((LPCSTR)data);
});
I provided hash function for CString, but compiler still returns errors:
error C2338: The C++ Standard doesn't provide a hash for this type.
error C2664: 'std::unordered_map<CString,CString,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const
_Kty,_Ty>>>::unordered_map(std::initializer_list<std::pair<const _Kty,_Ty>>,unsigned int,const std::hash<_Kty> &,const _Keyeq &,const std::allocator<std::pair<const _Kty,_Ty>> &)' : cannot convert argument 1 from 'std::unordered_map<CString,CString,std::function<size_t (const CString &)>,std::equal_to<_Kty>,std::allocator<std::pair<const
_Kty,_Ty>>>' to 'const std::unordered_map<CString,CString,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const
_Kty,_Ty>>> &'
Please tell me what I'm doing wrong ?
Something like this:
struct CStringHash
{
size_t operator () (const CString &s) const
{
return hash<string>()(static_cast<LPCSTR>(s));
}
};
Then declare the map like this:
unordered_map<CString, CString, CStringHash> map;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With