C++0x에 람다와 클로져가 추가된다고 합니다(via rein). 흠좀무.
Example: Write collection to console
For example, let’s say you want to write each of a collection of Widgets to the console.
// Writing a collection to cout, in today's C++, option 1:
for( vector<Widget>::iterator i = w.begin(); i != w.end(); ++i )
cout << *i << " ";
Or we can leverage that C++ already has a special-purpose ostream_iterator type that does what we want:
// Writing a collection to cout, in today's C++, option 2:
copy( w.begin(), w.end(),
ostream_iterator<const Widget>( cout, " " ) );
In C++0x, just use a lambda that writes the right function object on the fly:
// Writing a collection to cout, in C++0x:
for_each( w.begin(), w.end(),
[]( const Widget& w ) { cout << w << " "; } );
홍민희 님이 2008-03-30 18:15:17에 고쳤습니다.
람다에 클로져라.. 멋지네요ㅎㅎ
로 써도 같은건가요?
네, 예제의 세 가지 방식 모두 동일한 결과를 출력합니다.
호옹 매일 functor 만들면서 아 이거 어떻게 안 되나 했는데 좋은데요 !_!
정렬 등에 사용되는 비교 연산을 보다 쉽게 일반화할 수 있겠군요.; 근데 C++자체를 별로 안 써서 패스=3
이 이야기는 나온지 꽤 되었지요. C++0x 정리하다 만게 있는데.. 그거나 해볼까나.
Closer의 도입으로 boost::lambda는 역사의 뒤안길로 사라지겠군요.
(하지만 컴파일러가 지원해주지 않으면.. OTL)
나름 역사적 뒷북이지 않을까 생각해보삼… (이미 어떤 의미에서 흘러간 옛 언어일지도 모르니까요)
http://en.wikipedia.org/wiki/C%2B%2B0x
위 페이지를 보니 엄청나게 많은 변화가 예상되는군요.