@@ -28,8 +28,8 @@ auto setSoundL = [](Sound s) {
28
28
using namespace std::chrono;
29
29
30
30
setAlarm(steady_clock::now() + hours(1),
31
- s,
32
- seconds(30));
31
+ s,
32
+ seconds(30));
33
33
};
34
34
```
35
35
@@ -43,9 +43,9 @@ using namespace std::placeholders;
43
43
44
44
auto setSoundB =
45
45
std::bind(setAlarm,
46
- steady_clock::now() + 1h,
47
- _ 1,
48
- 30s);
46
+ steady_clock::now() + 1h,
47
+ _ 1,
48
+ 30s);
49
49
```
50
50
51
51
- 첫번째로 setSoundL은 param 타입을 명시적으로 알 수 있는데 반해서 setSoundB를 호출할 때는 placeholder
@@ -66,11 +66,11 @@ using namespace std:: placeholders;
66
66
67
67
auto setSoundB =
68
68
std::bind(setAlarm,
69
- std::bind(std::plus<steady_clock::time_point>(),
70
- steady_clock::now(),
71
- hours(1)),
72
- _1,
73
- seconds(30));
69
+ std::bind(std::plus<steady_clock::time_point>(),
70
+ steady_clock::now(),
71
+ hours(1)),
72
+ _1,
73
+ seconds(30));
74
74
```
75
75
76
76
다음으로 setAlarm이 오버로딩 되는 경우를 더 생각해 보자. 여기서 추가적인 문제가 발생한다.
@@ -92,11 +92,11 @@ using SetAlarm3ParamType = void(*)(Time t, Sound s, Duration d);
92
92
93
93
auto setSoundB =
94
94
std::bind(static_cast<SetAlarm3ParamType>(setAlarm),
95
- std::bind(std::plus<>,
96
- steady_clock::now(),
97
- h1),
98
- _1,
99
- 30s);
95
+ std::bind(std::plus<>,
96
+ steady_clock::now(),
97
+ h1),
98
+ _1,
99
+ 30s);
100
100
```
101
101
102
102
- 여기서 한가지 차이점이 또 발생한다. Lamda의 경우 내부에서 호출하는 setAlarm이 일반 함수이기 때문에 컴파
@@ -121,8 +121,8 @@ using namespace std::placeholders;
121
121
122
122
auto betweenB =
123
123
std::bind(std::logical_and<bool>(),
124
- std::bind(std::less_euqal<int>(), lowVal, _1),
125
- std::bind(std::less_equal<int>(), _1, highVal));
124
+ std::bind(std::less_euqal<int>(), lowVal, _1),
125
+ std::bind(std::less_equal<int>(), _1, highVal));
126
126
```
127
127
128
128
Lamda 버전이 더 짧을뿐 아니라 더 이해하기 쉽고 유지보수하기 쉽다는데 동의하기 바란다. :)
@@ -133,7 +133,7 @@ Lamda 버전이 더 짧을뿐 아니라 더 이해하기 쉽고 유지보수하
133
133
enum class CompLevel { Low, Normal, High };
134
134
135
135
Widget compress(const Widget& w,
136
- CompLevel lev);
136
+ CompLevel lev);
137
137
138
138
Widget w;
139
139
@@ -200,5 +200,5 @@ C++11 lamda에서는 이렇게 할 수 있는 방법이 없었다. 하지만 C++
200
200
201
201
```c++
202
202
auto boundPW = [pw](const auto& param)
203
- { pw(param); };
203
+ { pw(param); };
204
204
```
0 commit comments