-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_unorder_map.cc
58 lines (46 loc) · 1.16 KB
/
new_unorder_map.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <unordered_map>
using namespace std;
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);
}
};
namespace std {
template <>
struct hash<Key>
{
std::size_t operator()(const Key& k) const
{
using std::size_t;
using std::hash;
using std::string;
// Compute individual hash values for first,
// second and third and combine them using XOR
// and bit shifting:
return ((hash<string>()(k.first)
^ (hash<string>()(k.second) << 1)) >> 1)
^ (hash<int>()(k.third) << 1);
}
};
}
typedef std::unordered_map<Key,std::string> m6;
m6::diplaypoint(m6 p){
cout << p.first<<""<<p.second;
}
int main() {
m6 c1;
c1.insert(m6::value_type({"John", "Doe", 12}, "example"));
c1.insert(m6::value_type({"Mary", "Sue", 21}, "another"));
for (m6::iterator it = c1.begin();
it != c1.end(); ++it)
cout << it->first << ", " << it->second;
std::cout << std::endl;
return 0;
}