普通函数

int f( int a, int b ){return a + b;}
boost::bind( f, _1, 9 )( 1 )

成员函数

struct demo{int f( int a, int b ){return a + b;}};
demo a, &ra=a;
demo *p = &a;
boost::bind( &demo::f, a, _1, 20 )( 10 )

成员变量

typedef std::pair<int, std::string> pair_t;
pair_t p( 123, "string" );
boost::bind( &pair_t::first, p )();
boost::bind( &pair_t::second, p )();

函数对象

struct sf{int operator()( int a, int b ){return a + b;}};
boost::bind<int>( sf(), _1, _2 )( 11, 22 )

ref库 使用ref库包装对象的引用可以让bind 存储对象引用的拷贝,从而降低了拷贝的代价

变量:int g( int a, int b, int c ){return a + b + c;}
int x = 10;
boost::bind( g, _1, boost::cref( x ), boost::ref( x ) )( 11 );

函数对象:struct sf{int operator()( int a, int b ){return a + b;}};
sf af;
boost::bind<int>( boost::ref( af ), _1, _2 )( 11, 22 );

 

转载地址:http://blog.csdn.net/huang_xw/article/details/8452785

相关文章:

  • 2021-08-27
  • 2021-07-22
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-03-06
猜你喜欢
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-06-17
  • 2021-12-29
  • 2022-12-23
相关资源
相似解决方案