From 56d0a94ec84925605cf7ef6d74c5d055d57f50be Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Sep 2014 15:35:02 +0000 Subject: [PATCH] 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 --- docs/changes.txt | 1 + include/wx/string.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index adc5a5656a..60a6dd338e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/string.h b/include/wx/string.h index c15a80f0cc..05fc91a8ca 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -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 + +namespace std +{ + template<> + struct hash + { + size_t operator()(const wxString& s) const + { + return std::hash()(s.ToStdWstring()); + } + }; +} // namespace std + +#endif // C++11 + // --------------------------------------------------------------------------- // Implementation only from here until the end of file // ---------------------------------------------------------------------------