Commit 8fb4e8a15079f1bc402d1a0282be58cf8668f6a2
1 parent
37a77a62
Added bind example
Showing
16 changed files
with
35 additions
and
1 deletions
01-bind.cpp
0 → 100644
1 | +#include <iostream> | |
2 | +#include <functional> | |
3 | + | |
4 | +void fun(int arg1, int arg2) | |
5 | +{ | |
6 | + std::cout << arg1 << " " << arg2 << std::endl; | |
7 | +} | |
8 | + | |
9 | + | |
10 | +struct t | |
11 | +{ | |
12 | +void g(int arg1, int arg2) | |
13 | +{ | |
14 | + std::cout << arg1 << " " << arg2 << std::endl; | |
15 | +} | |
16 | +}; | |
17 | + | |
18 | +int main() | |
19 | +{ | |
20 | + auto f = std::bind(fun, 2 ,3); | |
21 | + f(); | |
22 | + | |
23 | + auto g = std::bind(fun, 2, std::placeholders::_1); | |
24 | + g(7); | |
25 | + g(77); | |
26 | + | |
27 | + auto h = std::bind(fun, std::placeholders::_2, std::placeholders::_1); | |
28 | + h(15,16); | |
29 | + | |
30 | + t ti; | |
31 | + auto o = std::bind(&t::g, &ti, std::placeholders::_1, 7); | |
32 | + o(17); | |
33 | +} | |
34 | + | ... | ... |
01-timer2.cpp renamed to 02-timer2.cpp
02-timer3.cpp renamed to 03-timer3.cpp
03-timer4.cpp renamed to 04-timer4.cpp
04-timer5.cpp renamed to 05-timer5.cpp
05-daytime1.cpp renamed to 06-daytime1.cpp
06-daytime2.cpp renamed to 07-daytime2.cpp
07-daytime3.cpp renamed to 08-daytime3.cpp
08-daytime4.cpp renamed to 09-daytime4.cpp
09-daytime5.cpp renamed to 10-daytime5.cpp
10-daytime6.cpp renamed to 11-daytime6.cpp
11-daytime7.cpp renamed to 12-daytime7.cpp
12-threads.cpp renamed to 13-threads.cpp
13-daytime8.cpp renamed to 14-daytime8.cpp
14-daytime9.cpp renamed to 15-daytime9.cpp
makefile
... | ... | @@ -4,7 +4,7 @@ CFLAGS=-ggdb -Wall -pedantic -D_REENTRANT -DASIO_STANDALONE -DASIO_HAS_CO_AWAIT |
4 | 4 | %: %.cpp |
5 | 5 | g++-10 -std=c++20 -fcoroutines $(CFLAGS) $< -o $@ -lpthread |
6 | 6 | |
7 | -EXECS = 00-timer1 01-timer2 02-timer3 03-timer4 04-timer5 05-daytime1 06-daytime2 07-daytime3 08-daytime4 09-daytime5 10-daytime6 11-daytime7 12-threads 13-daytime8 14-daytime9 | |
7 | +EXECS = 00-timer1 01-bind 02-timer2 03-timer3 04-timer4 05-timer5 06-daytime1 07-daytime2 08-daytime3 09-daytime4 10-daytime5 11-daytime6 12-daytime7 13-threads 14-daytime8 15-daytime9 | |
8 | 8 | |
9 | 9 | all: $(EXECS) |
10 | 10 | ... | ... |