2. 발표자 는 뉴규?
김연기
아.꿈.사 오후반 스터디 그룹 장소 예약 담당
(Pattern Oriented Software Architecture 2)
2008. 10 ~ Microsoft Visual C++ MVP
유콘시스템 Sw개발팀 지상관제 장비 SW 개발
잉카 인터넷 보안개발팀 업데이트 모듈 개발.
http://twitter.com/scor7910
http://scor7910.tistory.com
3. 차례
• 새롭게 추가 된 것들.
– Lambda
– R-Value Reference
– auto, decltype, constexpr
– Smart Pointer
• 참고자료.
• Q&A
11. Lambda –리턴-
• []()->리턴 타입{…}
transform(v.begin(), v.end(), front_inserter(d), [](int
n) -> double {
if (n % 2 == 0)
{
return n * n * n;
}
else
{
return n / 2.0;
}
});
12. Lambda –캡쳐-
• 상위 스코프({…})의 변수를 람다 구현내부
에서 사용할 수 있다.
• [변수1, 변수2] : 변수1, 변수2 캡쳐
• [&변수1, &변수2] : 변수1, 변수2 참조캡쳐
• [&] : 상위 스코프의 변수를 참조 캡쳐.
• [=] : 상위 스코프의 변수를 값 캡쳐.
13. Lambda –캡쳐-
int x = 4;
int y = 5;
cout << "Input: ";
cin >> x >> y;
v.erase(remove_if(v.begin(), v.end(), [x, y](int n)
{ return x < n && n < y; }), v.end());
int x = 4;
int y = 5;
for_each(v.begin(), v.end(), [=](int& r) mutable {
//값을 캡쳐하면 x,y는 const로 들어오지만 mutable 키워드로
//캡쳐된 변수를 변경가능한 변수로 만들어줌.
const int old = r;
r *= x * y;
x = y;
y = old;
});
14. Lambda –캡쳐-
int x = 4;
int y = 5;
cout << "Input: ";
cin >> x >> y;
v.erase(remove_if(v.begin(), v.end(), [&x, &y](int n)
{ return x < n && n < y; }), v.end());
int x = 4;
int y = 5;
for_each(v.begin(), v.end(), [&](int& r) {
const int old = r;
r *= x * y;
x = y;
y = old;
});