Mon code:
typedef pair Pair tr1::unordered_map h; h.insert(make_pair(Pair(0,0),true));
Erorr
undefined reference to `std::tr1::hash<std::pair >::operator()(std::pair) const'
Quelque chose que je dois réparer?
Merci
Cela est dû au fait qu’il n’y a pas de spécialisation pour std::tr1::hash
avec Key = std::pair
. Vous devez vous spécialiser std::tr1::hash
avec Key = std::pair
avant de déclarer tr1::unordered_map
. Cela se produit parce que std
ne sait pas comment hacher une pair
.
Vous std::tr1::hash<>
un exemple de spécialisation de std::tr1::hash<>
template <> struct std::tr1::hash > { public: size_t operator()(std::pair x) const throw() { size_t h = SOMETHING;//something with x return h; } };
Couru dans le même problème:
unordered_map , z> m1;
Quelques solutions de contournement sont:
unordered_map m1; // the first and second of the pair merged to a ssortingng // though ssortingng parsing may be required, looks same complexity overall unordered_multimap > m1; // second of the pair of the key went into value. // time complexity slightly increases deque> d1; // here x & y are of same type, z is stored as: d1[x][y] = z // space required is x * y, however time complexity is O(1)