0

I want to you use unordered_mapfor Memoization on a function f(row, int). Unfortunately, I get a weird compilation error (very long and cryptic).

#include <vector>
#include <unordered_map>
#include <utility>


using namespace std;

typedef vector<bool> row;

int main(void) {

    unordered_map< pair<int, row>, int > x;

}
Joachim
  • 3,210
  • 4
  • 28
  • 43

1 Answers1

2

The key type for std::unordered_map needs to have an implementation of std::hash, I'd guess your error is telling you that std::pair<int, row> does not have an std::hash implementation. I don't think the standard specifies a specialization of std::hash for std::pair so you'll need to provide your own.

mattnewport
  • 13,728
  • 2
  • 35
  • 39
  • Ok, thanks. Any ideas how to implement an effective hash function for a pair> ? – Joachim Apr 03 '15 at 00:09
  • The standard requires specializations of `std::hash` for both `int` and `std::vector` so you just need to combine them somehow, maybe like in this answer: http://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x - better support for building custom hash functions is proposed for a future version of the standard I believe. – mattnewport Apr 03 '15 at 00:27