binaryBigInt
binaryBigInt

Reputation: 1704

C++: Extend already created C struct with custom hash and equal functions to be usable in unordered_map

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

Answers (1)

numzero
numzero

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

Related Questions