Reputation: 1704
I have two projects, one is written in C and the other one in C++. I need to use a C-struct in my C++ program in a unordered_map. How can I extend the struct by a hash and compare function such that I don't always have to pass those functions to the unordered_map?
Upvotes: 0
Views: 48
Reputation: 2057
Define the ==
operator outside the struct (that’s allowed) and specialize std::hash
for your struct in a C++ file. See an example at cppreference: https://en.cppreference.com/w/cpp/utility/hash
Upvotes: 1