1

In Execution.cpp, I need to add unordered_map. I used the following instruction:

#include <unordered_map>

std::unordered_map<StringRef, std::unordered_map<StringRef, struct IntRel>> BinaryRel;

but it invokes the following errors:

/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>;
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
R.Omar
  • 645
  • 1
  • 6
  • 18
  • 4
    You forgot to define a hash function for StringRef, or perhaps #include an existing definition. – n. m. could be an AI Apr 01 '18 at 15:46
  • Possible duplicate of [C++ unordered\_map using a custom class type as the key](https://stackoverflow.com/questions/17016175/c-unordered-map-using-a-custom-class-type-as-the-key) – 273K Apr 01 '18 at 16:15

1 Answers1

0

You have to specialize std::hash for your StringRef type. For example:

#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;

}

Although I suggest better implementation of hashing function :D For this you can use one of existing specializations (std::hash<std::string> ? if your StringRef possibly contains std::string object).

Criss
  • 581
  • 5
  • 17