I'm trying to build an unordered map to contain points in n-dimensional
space. I understand that std::vector meets all the requirements for being a key in std::map, and yet this code does not compile. I get a long list of error messages, but this seems the most problematic:
error: no match for call to ‘(const std::hash<std::vector<int> >) (const std::vector<int>&)'.
Does anyone have any idea as to why g++ doesn't seem to think that std::vector<int> is hashable?
#include <vector>
#include <unordered_map>
#include <boost/functional/hash.hpp>
using namespace std;
typedef vector<int> point;
int main()
{
unordered_map<point, int>jugSpace;
vector<int> origin(3, 0);
jugSpace.insert( pair<point,int>(origin, 0) );
}
vector<int>as apointseems unnecessarily expensive. Sensible uses of points all traffic in points with the same number of dimensions, so the variable size of avector, and the resultant overhead, is generally not needed. I'd go with astructwith appropriate data members, or possible a template that takes the number of dimensions as a template argument and usesstd::arrayinternally. Of course, with either of these approaches you still have to make the point type hashable.