在Execution.cpp
,我需要添加unordered_map
。我使用了以下指令:
#include <unordered_map>
std::unordered_map<StringRef, std::unordered_map<StringRef, struct IntRel>> BinaryRel;
但它会调用以下错误:
/usr/include/c++/4.8/bits/functional_hash.h:58:12: error: declaration of ‘struct std::hash<llvm::StringRef>’
struct hash;
/usr/include/c++/4.8/bits/hashtable_policy.h:1082:53: error: invalid use of incomplete type ‘struct std::hash<llvm::StringRef>’
using __ebo_h1 = _Hashtable_ebo_helper<1, _H1>;
你必须专门为你的std::hash
类型StringRef
。例如:
#include <unordered_map>
struct StringRef {};
struct IntRel {};
namespace std {
template<>
struct hash<StringRef>
{
std::size_t operator()(const StringRef& s) const noexcept { return 0; }
};
}
int main()
{
std::unordered_map<StringRef, std::unordered_map<StringRef, struct IntRel>> BinaryRel;
}
虽然我建议更好地实现散列函数:D为此你可以使用现有的一个特化(std::hash<std::string>
?如果你的StringRef
可能包含std::string
对象)。