728x90
boost::bind 의 이용 예제.. 사실상 응용이라던가 더 복잡한 쓰임은 있지만 대략 이런 역활을 한다
는 것을 익힐 뿐이고 상세한 이용은 검색을 더 해보는 것이 좋을 듯. 실제 asio 에제를 보면 더 많이
, 여러기능이 쓰이는 것을 알 수 있다
예제
// start
#include "stdafx.h"
#include <regex>
#include <tuple>
#include <functional>
#include <boost/bind.hpp>
#include <boost/function.hpp>
int no_arg()
{
return 0;
}
struct one_arg
{
int operator () (int i) const
{
return i;
}
typedef int result_type;
};
struct two_arg
{
int val;
two_arg(int v) : val(v) {}
int f(int i, int j) const
{
return val + i + j;
}
};
class ref_arg
{
public:
void f(int& i)
{
++i;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int res = 0;
res = boost::BOOST_BIND(no_arg)();
one_arg arg1;
res = boost::BOOST_BIND(arg1, 2011)();
two_arg arg2(2011);
res = boost::BOOST_BIND(&two_arg::f, arg2, 1, 2)();
ref_arg arg3;
res = 0;
boost::BOOST_BIND(&ref_arg::f, arg3, _1)(res); // _1 은 첫번째 인자를
std::cout << res << std::endl; // output 1
res = 0;
boost::BOOST_BIND(&ref_arg::f, arg3, res);
std::cout << res << std::endl; // output 0
int n;
std::cin >> n;
return 0;
}
// end
728x90
'프로그래밍 > boost' 카테고리의 다른 글
| boost::mutex (0) | 2012.03.26 |
|---|---|
| boost::unordered set, map, mutiset, multimap (0) | 2012.03.26 |
| boost::mem_fn 예제에 std::tr1::tuple 예제의 조합 (0) | 2011.11.15 |
| boost::asio 비동기 서버/클라 step 1 (0) | 2011.11.09 |
| WorkQueue & Worker (0) | 2011.11.08 |
댓글