分类: C/C++
2015-08-12 17:36:07
- struct Key
- {
- std::string first;
- std::string second;
- int third;
- bool operator==(const Key &other) const
- { return (first == other.first
- && second == other.second
- && third == other.third);
- }
- };
- struct KeyHasher
- {
- std::size_t operator()(const Key& k) const
- {
- using std::size_t;
- using std::hash;
- using std::string;
- return ((hash<string>()(k.first)
- ^ (hash<string>()(k.second) << 1)) >> 1)
- ^ (hash<int>()(k.third) << 1);
- }
- };
- int main()
- {
- std::unordered_map<Key,std::string,KeyHasher> m6 = {
- { {"John", "Doe", 12}, "example"},
- { {"Mary", "Sue", 21}, "another"}
- };
- }