LangDev

프로그래밍 언어 개발에 관심 있는 사람들의 모임입니다.


C++0x에 람다와 클로져가 추가된다고 합니다.

2008-03-30 15:05:46

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에 고쳤습니다.

트랙백 주소: http://langdev.net/post/trackback/33

  1. How quickly does amoxicillin work. from Amoxicillin alternative.
  2. Best price for tramadol. from Tramadol hydrochloride.
  3. Valtrex. from Valtrex.
  4. Ephedrine. from Addiction to ephedrine.
  5. Vicodin addiction. from Vicodin.
  6. Prescription free amoxicillin. from Amoxicillin with no prescription.
  7. Ambien and memory loss. from Ambien no prescription.
  8. Cheapest cialis. from Cheapest cialis.
  1. 종현 2008-03-30 17:10:33

    람다에 클로져라.. 멋지네요ㅎㅎ

  2. mithrandir 2008-03-30 21:41:31
    // Writing a collection to cout, in C++0x:
    
    for_each( w.begin(), w.end(),
      []( const Widget& i ) { cout << i << " "; } );
    
    

    로 써도 같은건가요?

  3. 홍민희 2008-03-31 00:17:23

    네, 예제의 세 가지 방식 모두 동일한 결과를 출력합니다.

  4. 김광영/코에이 2008-03-31 00:04:11

    호옹 매일 functor 만들면서 아 이거 어떻게 안 되나 했는데 좋은데요 !_!

  5. 아침놀 2008-03-31 00:04:53

    정렬 등에 사용되는 비교 연산을 보다 쉽게 일반화할 수 있겠군요.; 근데 C++자체를 별로 안 써서 패스=3

  6. 까막 2008-03-31 04:47:22

    이 이야기는 나온지 꽤 되었지요. C++0x 정리하다 만게 있는데.. 그거나 해볼까나.

    Closer의 도입으로 boost::lambda는 역사의 뒤안길로 사라지겠군요.

    (하지만 컴파일러가 지원해주지 않으면.. OTL)

  7. 아겔-_- 2008-03-31 10:09:49

    나름 역사적 뒷북이지 않을까 생각해보삼… (이미 어떤 의미에서 흘러간 옛 언어일지도 모르니까요)

  8. 홍민희 2008-04-16 13:32:56

    http://en.wikipedia.org/wiki/C%2B%2B0x

    위 페이지를 보니 엄청나게 많은 변화가 예상되는군요.

목록보기

← PHP에서 “가짜” 클로저 쓰기 | Relation을 이용한 프로그래밍 →