bind简单示例代码

namespace
{
class placeholder_ {};
placeholder_ __1;
} template <typename R, typename T, typename Arg>
class simple_bind_t
{
private:
typedef R (T::*F)(Arg);
F f_;
T* t_;
Arg& a_; public:
simple_bind_t(F f, T* t, Arg &a)
: f_(f), t_(t), a_(a)
{} R operator()()
{
return (t_->*f_)(a_);
}
}; template <typename R, typename T, typename Arg>
class simple_bind_t2
{
private:
typedef R (T::*F)(Arg);
F f_;
T* t_; public:
simple_bind_t2(F f, T* t)
: f_(f), t_(t)
{} R operator()(Arg& a)
{
return (t_->*f_)(a);
}
}; template <typename R, typename T, typename Arg>
simple_bind_t<R, T, Arg> simple_bind(R (T::*f)(Arg), T* t, Arg& a)
{
return simple_bind_t<R, T, Arg>(f, t, a);
} template <typename R, typename T, typename Arg>
simple_bind_t2<R, T, Arg> simple_bind(R (T::*f)(Arg), T* t, placeholder_& a)
{
return simple_bind_t2<R, T, Arg>(f, t);
} class bind_test
{
public:
void print_string(const std::string str)
{
printf("%s", str.c_str());
}
}; void test()
{
bind_test t;
std::string h = "hehe\n";
simple_bind(&bind_test::print_string, &t, h)();
simple_bind(&bind_test::print_string, &t, __1)(h);
boost::function<void (const std::string)> f;
f = simple_bind(&bind_test::print_string, &t, __1);
f(h);
}

运行结果

test函数返回结果应该是:
hehe
hehe
hehe

最新文章

  1. ubuntu12.10 源更新出错(sudo apt-get update)
  2. 学习Uml开始
  3. Apache CXF自定义拦截器
  4. deerlet-redis-client添加集群支持,邀请各路大神和菜鸟加入。
  5. 限制su权限
  6. Cocos开发中性能优化工具介绍之使用Windows任务管理器
  7. 转:更改 centos yum 源
  8. visual studio插件 visual assistx
  9. OleDbCommand cmd.Parameters.AddWithValue 添加参数时需要按照存储过程参数的顺序加入
  10. hibernate-------&gt;第一个程序
  11. [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线,弧线,圆形)
  12. centos7下安装python3.6
  13. 『Python CoolBook』Cython_高效数组操作
  14. golang error信息转字符串 x := fmt.Sprintf(&quot;%s&quot;, err)
  15. studio配置本地gradle-x.x.x-all.zip
  16. 云中树莓派(3):通过 AWS IoT 控制树莓派上的 Led
  17. mysql 存储过程 与 循环
  18. 【转】细谈Redis和Memcached的区别
  19. Storm Trident状态
  20. Succession

热门文章

  1. for循环简单实例(打印乘法表,打印菱形)
  2. Log4net 配置实例
  3. 20154327 Exp1 PC平台逆向破解
  4. 成都Uber优步司机奖励政策(2月24日)
  5. 成都Uber优步司机奖励政策(1月15日)
  6. Java:break和continue关键字的作用
  7. spring源码-国际化-3.5
  8. 关于iOS和Android的安装包更新笔记
  9. Myeclipse - 问题集 - specified vm install not found
  10. 用wireshark查看 tcpdump 抓取的mysql交互数据