-
Notifications
You must be signed in to change notification settings - Fork 0
/
varusing.cpp
39 lines (33 loc) · 893 Bytes
/
varusing.cpp
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
#include <string>
#include <unordered_set>
class Customer
{
private:
std::string name;
public:
Customer(std::string const& n) : name(n){}
std::string getName() const {return name;}
};
struct CustomerEq{
bool operator()(Customer const& c1, Customer const& c2) const{
return c1.getName() == c2.getName();
}
};
struct CustomerHash{
std::size_t operator()(Customer const& c) const {
return std::hash<std::string>()(c.getName());
}
};
// Define a class that combines operator() for variadic base classes
template<typename... Bases>
struct Overloader : Bases...
{
using Bases::operator()...;//OK since C++17
};
int main()
{
//Combine hasher and equality for customers in one type
using CustomerOP = Overloader<CustomerHash, CustomerEq>;
std::unordered_set<Customer, CustomerHash, CustomerEq> coll1;
std::unordered_set<Customer, CustomerOP, CustomerOP> coll2;
}