简体   繁体   中英

Pair as a key in map for Memoization

I want to you use unordered_map for 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;

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM