boost::lambda

Tags:

메타 프로그래밍이 미친짓 같아 보이지만, 이런 라이브러리를 만들어낸다는건 정말 대단하다는 말 밖에는;;;

#include
#include
#include
#include
#include

#include
#include

using namespace std;
using namespace boost::lambda;

int main()
{
vector vi;
for (int i = 0; i < 10; i++) vi.push_back(i); cout << "before" << endl; copy(vi.begin(), vi.end(), ostream_iterator(cout, ” “));
for_each(vi.begin(), vi.end(), _1 += 1);

cout << endl << "after" << endl; for_each(vi.begin(), vi.end(), cout << _1 << ' '); cout << endl << "end of program" << endl; return EXIT_SUCCESS; } [/code] 결과는 [code] before 0 1 2 3 4 5 6 7 8 9 after 1 2 3 4 5 6 7 8 9 10 end of program [/code] 도대체 어떻게 임의의 코드를 쓰면 그걸 functor로 바꾼걸까 알 수가 없군요..

Comments

2 responses to “boost::lambda”

  1. 이원구 Avatar

    요새 boost library에 꽂히셨군요. :-)
    boost 코드를 직접 보기는 좀 어렵더군요. 기본 원리를 위한 코드보다 워낙 여러 비 표준 컴파일러들에 대한 배려들이 많아서…
    expression template에 대한 글을 찾아서 읽어보시면 도움이 되실 것 같네요. 좋은 글이 몇 개 있었는데 링크는 잃어버렸네요. -_-;;

  2. MKSeo Avatar
    MKSeo

    네… 제대로 꽂혔죠 ㅎㅎ. labmda 같은 것이 왜 없나 늘 궁금했고, boost::lambda의 존재를 알았지만 실제로 쓰는건 처음봤거든요. 도움말 감사합니다. ^^

Leave a Reply

Your email address will not be published. Required fields are marked *