Commit e02010c31daa3e1253ac33d269d2d8e39e7d229d
1 parent
b30744b4
unordered_set example with inline lambda
Showing
2 changed files
with
31 additions
and
2 deletions
examples09/07-closures/makefile
1 | -all: fun1 fun2 fun3 fun4 fun5 unordered_set3 | 1 | +all: fun1 fun2 fun3 fun4 fun5 unordered_set3 unordered_set4 |
2 | 2 | ||
3 | fun1: fun1.o | 3 | fun1: fun1.o |
4 | g++ -g -Wall $^ -o $@ | 4 | g++ -g -Wall $^ -o $@ |
@@ -37,7 +37,13 @@ unordered_set3.o: unordered_set3.cpp | @@ -37,7 +37,13 @@ unordered_set3.o: unordered_set3.cpp | ||
37 | unordered_set3: unordered_set3.o | 37 | unordered_set3: unordered_set3.o |
38 | g++ -g -Wall $^ -o $@ | 38 | g++ -g -Wall $^ -o $@ |
39 | 39 | ||
40 | +unordered_set4.o: unordered_set4.cpp | ||
41 | + g++ -std=c++2a -g -c -Wall $< -o $@ | ||
42 | + | ||
43 | +unordered_set4: unordered_set4.o | ||
44 | + g++ -g -Wall $^ -o $@ | ||
45 | + | ||
40 | .PHONY: clean | 46 | .PHONY: clean |
41 | 47 | ||
42 | clean: | 48 | clean: |
43 | - -rm fun1.o fun1 fun2.o fun2 fun3.o fun3 fun4.o fun4 fun5.o fun5 unordered_set3.o unordered_set3 | ||
44 | \ No newline at end of file | 49 | \ No newline at end of file |
50 | + -rm fun1.o fun1 fun2.o fun2 fun3.o fun3 fun4.o fun4 fun5.o fun5 unordered_set3.o unordered_set3 unordered_set4.o unordered_set4 | ||
45 | \ No newline at end of file | 51 | \ No newline at end of file |
examples09/07-closures/unordered_set4.cpp
0 → 100644
1 | +#include <functional> | ||
2 | +#include <unordered_set> | ||
3 | +using namespace std; | ||
4 | +#include "employee.h" | ||
5 | + | ||
6 | +int main() { | ||
7 | + Employee Ben("Ben", "Keller", "000-00-0000"); | ||
8 | + Employee Bill("Bill", "McQuain", "111-11-1111"); | ||
9 | + Employee Dwight("Dwight", "Barnette", "888-88-8888"); | ||
10 | + | ||
11 | + unordered_set<Employee, decltype([](const Employee &o) { | ||
12 | + return std::hash<std::string>()(o.FirstName) ^ | ||
13 | + (std::hash<std::string>()(o.LastName) << 1) ^ | ||
14 | + (std::hash<std::string>()(o.ID) << 2); | ||
15 | + })> | ||
16 | + S; | ||
17 | + S.insert(Bill); | ||
18 | + S.insert(Dwight); | ||
19 | + S.insert(Ben); | ||
20 | + | ||
21 | + for (auto i : S) | ||
22 | + cout << i << endl; | ||
23 | +} |