QString
のキーとして使用しようとしていますstd::unordered_map
が、エラーが発生します:
エラー C2280: 'std::hash<_Kty>::hash(const std::hash<_Kty> &)': 削除された関数を参照しようとしています
QHash
マップの値の型がコピーできないため、切り替えることができません 。これを機能させる方法はありますか?
問題は、std::hash<QString>()
専門性がないことです。dbj2アルゴリズムに基づいて、適度に優れたパフォーマンスで独自のものを定義するのは簡単です。
#include <QString>
#include <unordered_map>
namespace std
{
template<> struct hash<QString>
{
std::size_t operator()(const QString& s) const noexcept
{
const QChar* str = s.data();
std::size_t hash = 5381;
for (int i = 0; i < s.size(); ++i)
hash = ((hash << 5) + hash) + ((str->row() << 8) | (str++)->cell());
return hash;
}
};
}
QString
aで aを使用するファイルにそれを含めるstd::unordered_map
と、エラーはなくなります。