unordered_set.cpp
912 Bytes
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
#include <functional>
#include <unordered_set>
using namespace std;
#include "employee.h"
struct EmpHash
{
std::size_t operator()(const Employee & o) const
{
return std::hash <std::string>()(o.FirstName)
^ (std::hash <std::string>()(o.LastName) << 1)
^ (std::hash <std::string>()(o.ID) << 2);
}
};
void EmpsetPrint (const unordered_set < Employee, EmpHash > S, ostream & Out);
int
main ()
{
Employee Ben ("Ben", "Keller", "000-00-0000");
Employee Bill ("Bill", "McQuain", "111-11-1111");
Employee Dwight ("Dwight", "Barnette", "888-88-8888");
unordered_set <Employee, EmpHash> S;
S.insert (Bill);
S.insert (Dwight);
S.insert (Ben);
EmpsetPrint (S, cout);
}
void
EmpsetPrint (const unordered_set <Employee, EmpHash> S, ostream & Out)
{
unordered_set <Employee, EmpHash>::const_iterator It;
for (It = S.begin (); It != S.end (); ++It)
Out << *It << endl;
}