Move definition of std::hash< wxString >

This commit is contained in:
Paul Licameli 2019-02-28 12:22:25 -05:00
parent 74128156bf
commit 961882838f
6 changed files with 23 additions and 16 deletions

View File

@ -46,9 +46,27 @@
#include <type_traits>
#include <vector>
#include <wx/debug.h> // for wxASSERT
#include <wx/string.h> // type used in inline function
#include <wx/version.h> // for wxCHECK_VERSION
class wxString;
#if !wxCHECK_VERSION(3, 1, 0)
// For using std::unordered_map on wxString
namespace std
{
template<typename T> struct hash;
template<> struct hash< wxString > {
size_t operator () (const wxString &str) const // noexcept
{
auto stdstr = str.ToStdWstring(); // no allocations, a cheap fetch
using Hasher = hash< decltype(stdstr) >;
return Hasher{}( stdstr );
}
};
}
#endif
// ----------------------------------------------------------------------------
// TODO: I'd imagine this header may be replaced by other public headers. But,
// to try and minimize more changes to the base code, we can use this

View File

@ -17,6 +17,7 @@
#include <wx/mstream.h> // member variables
#include <unordered_map>
#include "audacity/Types.h"
class wxFFile;
class AudacityProject;

View File

@ -33,6 +33,8 @@
#include "Audacity.h"
#include "Languages.h"
#include "audacity/Types.h"
#include <wx/defs.h>
#include <wx/intl.h>
#include <wx/textfile.h>

View File

@ -637,22 +637,6 @@ make_iterator_range( const Container &container )
return { container.begin(), container.end() };
}
#if !wxCHECK_VERSION(3, 1, 0)
// For using std::unordered_map on wxString
namespace std
{
template<typename T> struct hash;
template<> struct hash< wxString > {
size_t operator () (const wxString &str) const // noexcept
{
auto stdstr = str.ToStdWstring(); // no allocations, a cheap fetch
using Hasher = hash< decltype(stdstr) >;
return Hasher{}( stdstr );
}
};
}
#endif
// A utility function building a container of results
template< typename Container, typename Iterator, typename Function >
Container transform_range( Iterator first, Iterator last, Function &&fn )

View File

@ -39,6 +39,7 @@
#include "widgets/wxPanelWrapper.h" // to inherit
#include <unordered_map>
#include "audacity/Types.h"
class wxArrayString;
class wxComboBox;

View File

@ -21,6 +21,7 @@ LRN
#include "../FileNames.h"
#include <unordered_map>
#include "audacity/Types.h"
class wxArrayStringEx;