boost에서 lambda 와 function 의 사용

할 말을 잃음;;;
역쉬 C++ !!

#include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/function.hpp>

using namespace std;
using namespace boost;
using namespace boost::lambda;

void func(function<int(int, int)> f, int i, int j)
{
    cout << f(i, j) << endl;
}

int main(int argc, char **argv)
{
    func(_1 + _2, 1, 2);
    func(_1 - _2, 1, 2);

    return EXIT_SUCCESS;
}

_1이나 _2가 컴파일타임에 코드로 바뀌는 것들이나 function<int(int, int)> 와 같은 식의 코딩이 가능한 메타프로그래밍이라니요!!!! 감격 ㅠ.ㅜ

Similar Posts:

Post a Comment

Your email is never published nor shared.