How to do same thing for map?

when i tried same method for map…the compiler shows error…how to do for it??..
also one more thing…why unordered map doesn’t work without hashfxn when pair<int,int> is used as key?

To be able to use std::unordered_map (or one of the other unordered associative containers) with a user-defined key-type, you need to define two things:

  1. A hash function ; this must be a class that overrides operator() and calculates the hash value given an object of the key-type. One particularly straight-forward way of doing this is to specialize the std::hash template for your key-type.
  2. A comparison function for equality ; this is required because the hash cannot rely on the fact that the hash function will always provide a unique hash value for every distinct key (i.e., it needs to be able to deal with collisions), so it needs a way to compare two given keys for an exact match. You can implement this either as a class that overrides operator() , or as a specialization of std::equal , or – easiest of all – by overloading operator==() for your key type (as you did already).

The difficulty with the hash function is that if your key type consists of several members, you will usually have the hash function calculate hash values for the individual members, and then somehow combine them into one hash value for the entire object. For good performance (i.e., few collisions) you should think carefully about how to combine the individual hash values to ensure you avoid getting the same output for different objects too often.

and how to do it for a map… for example struct node{string s; int i; char c; }; how to do for map<node,int>

how to make map<node,int>??

some other useful things:
https://codeforces.com/blog/entry/62393
http://www.cplusplus.com/reference/unordered_map/unordered_map/

u can use a map instead of unordered, but u will need a hash function

https://www.techiedelight.com/use-custom-objects-keys-std-map-cpp/
u will get all the methods here

ok…thank u very much