简单的bind实现
来源:互联网 发布:淘宝媒体公司招聘主播 编辑:程序博客网 时间:2024/06/06 04:31
#include "main.h"#include "iostream"#include <functional>using namespace std;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_bind1(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 main(){bind_test t;std::string h = "hello\n";simple_bind1(&bind_test::print_string, &t, h)();simple_bind(&bind_test::print_string, &t, _1)(h);function< void(const std::string)> f;f = simple_bind(&bind_test::print_string, &t, _1);f(h);getchar();}
0 0
- 简单的bind实现
- boost bind及function的简单实现
- C++的杂七杂八:如何实现一个简单的bind
- 函数bind的实现
- weak bind的std实现
- javascript---bind的实现方法
- js的call和bind等原型方法的简单实现
- C++通过bind,lambda表达式等实现简单的异步函数调用模型
- std::bind,std::cref的简单使用
- bind及function的简单举例
- 模拟TR1中bind的实现
- Scala callccinterpreter 的bind函数实现
- debian下bind+mysql+DLZ的实现
- 详细解析boost中bind的实现
- 详细解析boost中bind的实现 .
- DNS服务及基于BIND的实现
- 详细解析boost中bind的实现
- DNS服务及基于BIND的实现
- only a type can be imported: XXX resolves to a package
- 在信息窗口添加图片按钮(百度地图)
- 算法系列之二十二:离散傅立叶变换之听声音破解电话号码
- 结构体的长度计算
- java编码习惯
- 简单的bind实现
- android 往dialog中加入listview,并实现listview中item的点击事件
- VC之键盘响应相关
- JVM,JRE,JDK
- 各种排序算法的实现-3(2路插入排序)
- android SpannableString使用详解
- DSP 学习指南
- 关于arrayList的add和addall
- android native开发环境搭建