Home:ALL Converter>FInd function in unordered_map with custom classes

FInd function in unordered_map with custom classes

Ask Time:2015-04-21T16:11:54         Author:user4089193

Json Formatter

I am using std::unordered_map with custom classes as shown below. I have correctly initialised and set up the hasher function. What I want to know is how to use the find function and what will it return? I am confused as the reference doc says that for the unordered_map the value acts as the key.

SO was wondering what the iterator would point to in the case of below find function

class xyz {
public:
 int x;
 int y;
 int z;

//Required stuff
.
.
.
}

// Required Stuff
.
.
.

int main()
{
  std::unordered_map<class xyz, std::string, KeyHasher> dummy = {
    { {10, 11, 12}, "example"},
    { {2, 3, 21}, "another"}
  };
  std::unordered_map<xyz, std::string, keyHasher>::const_iterator got = dummy.find({2, 3, 21});

  //What will find return here? Is it the pointer to string "another"?

}

I have referred the following for basic setup of the custom classes. C++ unordered_map using a custom class type as the key

http://www.cplusplus.com/reference/unordered_set/unordered_set/find/

Author:user4089193,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29766486/find-function-in-unordered-map-with-custom-classes
yy