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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.