Specialize std::hash<> for wxString when using C++11.

This allows to use wxString as key type of std::unordered_{map,hash} out of
the box.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77518 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-09-02 15:35:02 +00:00
parent 73e915a573
commit 56d0a94ec8
2 changed files with 23 additions and 0 deletions

View File

@ -43,6 +43,7 @@ All:
- Define wxOVERRIDE as override for supporting compilers (Thomas Goyne).
- Allow specifying custom comparator for wxSortedArrayString (Catalin Raceanu).
- Add wxDateTime::GetWeekBasedYear().
- Specialize std::hash<> for wxString when using C++11.
Unix:

View File

@ -3915,6 +3915,28 @@ wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData&, wxCMP_CHAR_CSTRDATA)
#undef wxCMP_CHAR_CSTRDATA
#undef wxCMP_WCHAR_CSTRDATA
// ----------------------------------------------------------------------------
// Implement hashing using C++11 std::hash<>.
// ----------------------------------------------------------------------------
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
#include <functional>
namespace std
{
template<>
struct hash<wxString>
{
size_t operator()(const wxString& s) const
{
return std::hash<std::wstring>()(s.ToStdWstring());
}
};
} // namespace std
#endif // C++11
// ---------------------------------------------------------------------------
// Implementation only from here until the end of file
// ---------------------------------------------------------------------------