[英]Pair as a key in map for Memoization
I want to you use unordered_map
for Memoization on a function f(row, int)
. 我想让您对函数
f(row, int)
使用unordered_map
进行记忆化。 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. std::unordered_map
的密钥类型需要具有std::hash
的实现,我想您的错误是告诉您std::pair<int, row>
没有std::hash
实现。 I don't think the standard specifies a specialization of std::hash
for std::pair
so you'll need to provide your own. 我认为标准没有为
std::pair
指定std::hash
的特殊化,因此您需要提供自己的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.