Answer the question
In order to leave comments, you need to log in
How can a union be used as the key of an unordered_map?
There is such a union:
union ObjectPos {
unsigned short x;
unsigned short y;
}
std::unordered_map<ObjectPos , Object*> objects;
Answer the question
In order to leave comments, you need to log in
You need to use a structure of two short values. For it, you will already need to define the hash function calculations, for example like this:
struct MyStruct {
unsigned short x;
unsigned short y;
};
template<>
struct std::hash<MyStruct> {
std::size_t operator()(MyStruct const& s) const noexcept {
return ((size_t)s.x << 16) | s.y;
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question