프로그램언어/boost
[ Boost ] boost::bind Part2
에블릿
2011. 5. 12. 18:14
Boost 목록
링크 : http://tingcobell.tistory.com/295
boost::bind part1 에서는 간단한 예제를 통해서 사용법에 대해 이야기 하고 있습니다. 이번에는 boost::ref 와 boost::cref에 대해서 이야기 하려고 합니다.
변수 i 에 어떠한 임의의 값을 저장한 후 함수 객체을 이용하여 함수 객체를 저장한 레퍼런스에 boost::ref 와 boost::cref 에 복사하여 사용합니다.
링크 : http://tingcobell.tistory.com/295
boost::bind part1 에서는 간단한 예제를 통해서 사용법에 대해 이야기 하고 있습니다. 이번에는 boost::ref 와 boost::cref에 대해서 이야기 하려고 합니다.
int i = 5;
bind( f, ref( i ), _1 );
bind( f, cref(42) _1 );
변수 i 에 어떠한 임의의 값을 저장한 후 함수 객체을 이용하여 함수 객체를 저장한 레퍼런스에 boost::ref 와 boost::cref 에 복사하여 사용합니다.
#include <boost/bind.hpp>
#include <iostream>
#include <boost/detail/lightweight_test.hpp>
struct X
{
short operator()(short &r) const { return ++r; }
int operator()( int a, int b) { return a - b ; }
};
int main()
{
short i(6);
int k(2);
BOOST_TEST( boost::bind<short>( X(), boost::ref(i))() == 7 );
return 0;
}