C++ 0x 새소식 – lambda 와 closure

Hurb Sutter의 블로그인 Sutter’s Mill에 이런 포스팅이 올라왔음

The ISO C++ committee met in Bellevue, WA, USA on February 24 to Mar 1. Here’s a quick summary of what we did (with links to the relevant papers to read for more details), and information about upcoming meetings.

Lambda functions and closures (N2550)

For me, easily the biggest news of the meeting was that we voted lambda functions and closures into C++0x. I think this will make STL algorithms an order of magnitude more usable, and it will be a great boon to concurrent code where it’s important to be able to conveniently pass around a piece of code like an object, to be invoked wherever the program sees fit (e.g., on a worker thread).

C++ has always supported this via function objects, and lambdas/closures are merely syntactic sugar for writing function object. But, though “merely” a convenience, they are an incredibly powerful convenience for many reasons, including that they can be written right at the point of use instead of somewhere far away.

요약하자면 지난 ISO C++ commitee에서 승인된 C++의 새 명세 중 하나로 lambda와 closure가 추가되었다는 것. 이제 예전에 BOOST PP를 사용해가면서 rein이 반 어거지로 구현했던 C++의 closure 구현은 삽질이 되는 날이 다가오게 되었다. (좀 근 미래의 일이긴 하지만 그래도 미래의 일이라는데 위안을)

일단은 Java의 익명 함수나 C#의 delegate 비슷한 기능을 위해서 boost::lambda 를 쓰거나 rein이 한 것처럼 closure 를 정의하는 삽질을 안해도 될 듯함.

여튼 이 얘기를 IRC에 붙여놓고 나온 Berryz WebShare 개발자 채널의 반응 (길어서 접었음)

[13:26:08] <rein> C++ 0x now has lambda
[13:26:11] <rein> & closure
[13:26:39] <i_k_> !!!!!!!!!!!!
[13:26:45] <i_k_> 이제
[13:26:46] <i_k_> C++은
[13:26:51] <i_k_> 아무도 배울수없는 언어가되었음
[13:29:13] <A_y_> …
[13:29:28] <A_y_> 무서운듯
[13:30:03] <rein> 근데 설명된 문법이
[13:30:04] <rein> 딱
[13:30:09] <rein> Java 익명함수 수준
[13:30:21] <rein> http://herbsutter.spaces.live.com/Blog/cns!2D4327CC297151BB!785.entry
[13:30:26] <i_k_> 그정도면 충분하지않나여
[13:30:31] <i_k_> 근데
[13:30:32] <rein> 차고 넘침
[13:30:33] <i_k_> 그거들어오는순간
[13:30:38] <i_k_> 컴파일러가 안만들어짐
(중략)
[13:33:42] <A_y_> c++은 이제
[13:33:50] <A_y_> 양파 같은 언어 같은듯
[13:34:01] <r_c_-_r> ㅋㅋㅋ
[13:34:08] <r_c_-_r> MMORPG 됐음
[13:34:14] <i_k_> 양파..
[13:34:15] <i_k_> 라기보다
[13:34:16] <r_c_-_r> 신규진입자는 영원히 기존 고렙들을 못따라잡는
[13:34:21] <i_k_> 굿
[13:34:23] <A_y_> 굳
[13:35:50] <i_k_> C#에
[13:35:53] <A_y_> …
[13:35:54] <i_k_> Y combinator짜는
[13:35:54] <rein> C#덤벼
[13:35:54] <A_y_> 전 아직도
[13:35:55] <i_k_> 예제가
[13:35:55] <rein> …
[13:35:56] <i_k_> 있더라구요
[13:35:57] <A_y_> 메타템플릿에서
[13:35:59] <rein> …
[13:35:59] <A_y_> 방황하는 쪼렙인데
[13:36:01] <rein> Y combinator
[13:36:03] <A_y_> 마치 뭐랄까
[13:36:04] <i_k_> C++은
[13:36:05] <rein> TMP로 만들 수 있지 않나
[13:36:07] <A_y_> C++ MMORPG에서
[13:36:08] <i_k_> 더 쉽게될듯
[13:36:09] <i_k_> tmp ?
[13:36:11] <A_y_> 렙업은 힘든데
[13:36:14] <A_y_> 만렙이 늘어난
[13:36:16] <A_y_> 그런 기분인듯
[13:36:17] <i_k_> ㅇㅇ
[13:36:19] <i_k_> 아직
[13:36:21] <i_k_> 10렙인데
[13:36:21] <rein> 템플릿으로 Y comb. 될듯
[13:36:24] <i_k_> 아웃랜드가 열렸음
[13:36:25] <r_c_-_r> 으하하하하하하하

요약하자면,

  • 안 그래도 멀티 패러다임 언어인 C++에 기정사실이지만 패러다임이 하나 추가
  • boost::lambda, boost::function, boost::functional을 통해 일부 구현가능했지만 문법적인 지원을 얻었음

그래도 C++ 위주의 개발을 해본 사람들이 있는 채널이라서 그런지 상당히 우호적인(?) 반응입니다…