Content deleted Content added
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
|||
Line 171:
==Usage example==
<
#include <iostream>
#include <string>
Line 197:
return 0;
}
</syntaxhighlight>
==Custom hash functions==
To use custom objects in std::unordered_map, a custom hash function must be defined. This function takes a const reference to the custom type and returns a size_t
<
#include <unordered_map>
Line 211:
}
};
</syntaxhighlight>
The user defined function can be used as is in std::unordered_map, by passing it as a template parameter
<
Or can be set as the default hash function by specializing the std::hash function
<
namespace std {
template <>
Line 230:
//...
std::unordered_map<X,int> my_map;
</syntaxhighlight>
==References==
|