I want to declare :
std::unordered_map<CString, CString> m_mapMyMap;
But when I build I got an error telling me that the standard C++ doesn't provide a hash function for CString, while CString have the (LPCSTR) operator.
How do I properly implement a hash function for CString?
Based on the MS STL implementation for
std::string
I created the following methods which can be used forstd::unordered_set
andstd::unordered_map
:Or even more generic:
std::unordered_map use std::hash<> that does not use
(LPCSTR)
operator.You need to redefine hash function:
But for better performance use std::string instead CString for key.