C++20 Concept Check Failing with std::unordered_map Key Type - Need Help Debugging
I'm converting an old project and I'm having an issue where a C++20 concept check on my custom key type for an `std::unordered_map` fails, and I'm not sure why. Iโve defined the key type as follows: ```cpp struct MyKey { int id; std::string name; bool operator==(const MyKey& other) const { return id == other.id && name == other.name; } }; namespace std { template <> struct hash<MyKey> { std::size_t operator()(const MyKey& k) const { return std::hash<int>()(k.id) ^ std::hash<std::string>()(k.name); } }; } ``` Then I declared my unordered map like this: ```cpp std::unordered_map<MyKey, int> myMap; ``` When I try to compile, I get the following error message: ``` error: no matching function for call to โstd::hash<MyKey>::operator()(const MyKey&) constโ ``` I know that `std::unordered_map` requires a hash function for the key type, and the `std::hash` specialization should be working. Iโve also tried adding a concept constraint to ensure that my key type meets the requirements, but it still fails: ```cpp template <typename T> concept Hashable = requires(T t) { { std::hash<T>()(t) } -> std::same_as<std::size_t>; }; ``` Even with that, Iโm getting errors related to the concept check. Iโve verified that I have the necessary includes, and my environment is set up with g++ 10 with C++20 support enabled. What am I missing here? How can I ensure that my custom key type works seamlessly with `std::unordered_map`? Any advice or pointers on debugging this would be greatly appreciated! Thanks in advance! I'm working in a macOS environment. Any ideas what could be causing this?