- 浏览: 725733 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (1044)
- 数据结构 (36)
- UML与设计模式 (42)
- c++ (87)
- rust (36)
- Qt (41)
- boost模板元编程 (43)
- Linux (77)
- 汇编 (4)
- 其它 (2)
- 烹饪 (3)
- unix c / socket (73)
- 软件工程 (4)
- shell (53)
- Python (37)
- c++ primer 5th(c++11) (22)
- 数据库/MySQL (27)
- 数据存储 (4)
- lisp (7)
- git (4)
- Utility (3)
- CDN与DNS (54)
- Http (53)
- php (7)
- nginx/lua/openresty (41)
- redis (11)
- TCP/IP (16)
- 互联网 (6)
- kernel (2)
- go (34)
- 区块链 (43)
- 比特股 (13)
- 以太坊 (23)
- 比特币 (23)
- 密码学 (10)
- EOS (53)
- DAG (1)
- docker (1)
- filecoin (7)
- solidity (64)
- ipfs (8)
- 零知识证明 (1)
- openzeppelin (3)
- java (1)
- defi (7)
最新评论
bind并不是一个单独的类或函数,而是非常庞大的家族,依据绑定的参数个数和要绑定的调用对象类型,总共有十个不同的形式,但它们的名字都叫bind.
bind接受的第一个参数必须是一个可调用对象f,包括函数,函数指针,函数对象和成员函数,之后bind接受最多9个参数,参数的数量必须与f的参数数量相等
_1,_2这些一直可以到9,是占位符,必须在绑定表达式中提供函数要求的所有参数,无论是真实参数还是占位符均可以。占位符不可以超过函数参数数量。
绑定普通函数:
绑定成员函数:
bind接受的第一个参数必须是一个可调用对象f,包括函数,函数指针,函数对象和成员函数,之后bind接受最多9个参数,参数的数量必须与f的参数数量相等
_1,_2这些一直可以到9,是占位符,必须在绑定表达式中提供函数要求的所有参数,无论是真实参数还是占位符均可以。占位符不可以超过函数参数数量。
绑定普通函数:
#include<boost/bind.hpp> #include<iostream> using namespace std; using namespace boost; void fun(int a,int b){ cout << a+b << endl; } int main() { bind(fun,1,2)();//fun(1,2) bind(fun,_1,_2)(1,2);//fun(1,2) bind(fun,_2,_1)(1,2);//fun(2,1) bind(fun,_2,_2)(1,2);//fun(2,2) bind(fun,_1,3)(1);//fun(1,3) } 3 3 3 4 4
绑定成员函数:
#include<boost/bind.hpp> #include<iostream> #include<vector> #include<algorithm> using namespace boost; using namespace std; struct point { int x,y; point(int a=0,int b=0):x(a),y(b){} void print(){ cout << "(" << x << "," << y << ")\n"; } void setX(int a){ cout << "setX:" << a << endl; } void setXY(int x,int y){ cout << "setX:" << x << ",setY:" << y << endl; } void setXYZ(int x,int y,int z){ cout << "setX:" << x << ",setY:" << y << "setZ:" << z << endl; } }; int main() { point p1,p2; bind(&point::setX,p1,_1)(10); bind(&point::setXY,p1,_1,_2)(10,20); bind(&point::setXYZ,p2,_1,_2,_3)(10,20,30); vector<point> v(10); //for_each的时候只需要_1就可以了 for_each(v.begin(),v.end(),bind(&point::print,_1)); for_each(v.begin(),v.end(),bind(&point::setX,_1,10)); for_each(v.begin(),v.end(),bind(&point::setXY,_1,10,20)); for_each(v.begin(),v.end(),bind(&point::setXYZ,_1,10,20,30)); } setX:10 setX:10,setY:20 setX:10,setY:20setZ:30 (0,0) (0,0) (0,0) (0,0) (0,0) (0,0) (0,0) (0,0) (0,0) (0,0) setX:10 setX:10 setX:10 setX:10 setX:10 setX:10 setX:10 setX:10 setX:10 setX:10 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30 setX:10,setY:20setZ:30
发表评论
-
multi_index_container
2018-08-11 13:04 415根据不同的类中不同的字段排序 #include < ... -
program_options读命令行和配置文件
2018-07-27 11:30 806#include <boost/program_opti ... -
centos下boost安装
2014-03-27 09:28 1018./booststarp.sh //这里的一些错误不用管 ... -
GC的改良
2013-10-17 22:05 531分代回收:对分配不久,诞生时间较短的“年龄”对象进行重点扫描, ... -
GC与引用记数
2013-10-16 21:57 666根(Root)就是判断对象是否可被引用的起始点。至于哪里才是根 ... -
boost 信号槽
2011-06-08 23:43 2282#include<boost/signals2.hp ... -
boost reference_wrapper
2011-06-05 21:07 1530reference_wrapper是一个引用类型的包装器 ... -
元编程
2011-06-02 22:46 899元编程的最大特点在于:某些用户自定义的计算可以在程序翻译期进行 ... -
参数化虚拟性
2011-06-02 22:17 820#include<iostream> usi ... -
boost any与variant
2011-05-31 15:55 2392any:是一种只能容纳一个元素的容器,但这个元素可以是任意类型 ... -
traits
2011-05-30 16:43 760#include<iostream> usi ... -
动静多态
2011-05-30 15:40 1039由于继承||虚函数在运行期进程处理,这种多态叫动多态。 模板允 ... -
局部特化
2011-05-29 16:27 1008局部特化并不会引入一个新的模板,它只对原来模板(基本模板)进行 ... -
类模板与模板类
2011-05-29 16:08 6821.类模板:该类是一个模板,他代表的是:整个类家族的参数化描述 ... -
boost tuple
2011-05-27 15:03 1045tuple(元组):定义了一个有固定数目元素的容器,其中的每个 ... -
boost array
2011-05-27 00:06 909array本质上是一个对静态数组的包装,没有构造函数,不能指定 ... -
单元测试
2011-05-23 22:00 855test库提供了一个最小化的测试套件minimal test. ... -
boost StaticAssert
2011-05-23 21:42 904static_assert库把断言的诊断时刻由运行期提前到编译 ... -
boost正则表达式
2011-05-17 23:10 2763xpressive是boost的正则表达式库,它比boost. ... -
为什么模板要写在.h里面
2011-05-13 18:02 1075//test.h template<typena ...
相关推荐
boost stl一些常用函数的使用训练
算是一个消息处理框架吧,用于说函数对象function与bind的基本用法; 比较适合入门boost的function与bind的基本用法
3.2 Boost.Bind 3.3 Boost.Ref 3.4 Boost.Function 3.5 Boost.Lambda 3.6 Exercises Chapter 4: Event Handling 4.1 General 4.2 Signals 4.3 Connections 4.4 Exercises Chapter 5: String Handling 5.1 General ...
基于boost的asio封装的高性能TCP服务器。asio已经有很好的事件封装机制,只有底层...3、运用最新的C++11语法规范实现全部代码(lamda override bind) 原创博客地址: http://blog.csdn.net/wang19840301 欢迎留言讨论
汉化 boost 文档,致力 boost 推广。 如果你对本项目有兴趣,欢迎加入,相关说明请查阅项目论坛: https://groups.google.com/ 到目前为止,各人贡献的译文如下: 贡献者 贡献的译文 alai04 accumulators, any, ...
Björn Karlsson为中级至高级的C++开发者描述了所有58...可在调用点进行定义的函数对象:Boost.Bind 和 Boost.Lambda 更灵活的回调机制:Boost.Function 可管理的信号和响应动作(又称为Observer模式):Boost.Signals
boost库基本使用方法,使用cmake2.6构建工程,包含nocopyable\singleton\asio\filesystem\bind\thread\futuer等
practice solutions for performing type conversions and lexical conversions <br...Boost.Bind and Boost.Lambda <br>More flexible callbacks with Boost.Function <br>Managed signals and slots (a.k.a....
practice solutions for performing type conversions and lexical conversions <br...Boost.Bind and Boost.Lambda <br>More flexible callbacks with Boost.Function <br>Managed signals and slots (a.k.a....
本人看完此资料,受益非浅,拿出来大家一起分享,一起交流心得。
在阅读本书的过程中,读者需要注意本书的排版风格,作者在写作过程中,大量使用了函数名和关键字,例如,“删除”使用了函数名“delete”,“绑定”使用了函数名“bind”,“类型定义”使用了关键字“typedef”等等...
atomic-boost-1.70.0.tar.gz boostorg-beast-boost-1.70.0.tar.gz boostorg-bimap-boost-1.70.0.tar.gz boostorg-bind-boost-1.70.0.tar.gz boostorg-build-boost-1.70.0.tar.gz boostorg-callable_traits-boost-...
atomic-boost-1.70.0.tar.gz boostorg-beast-boost-1.70.0.tar.gz boostorg-bimap-boost-1.70.0.tar.gz boostorg-bind-boost-1.70.0.tar.gz boostorg-build-boost-1.70.0.tar.gz boostorg-callable_traits-boost-...
atomic-boost-1.70.0.tar.gz boostorg-beast-boost-1.70.0.tar.gz boostorg-bimap-boost-1.70.0.tar.gz boostorg-bind-boost-1.70.0.tar.gz boostorg-build-boost-1.70.0.tar.gz boostorg-callable_traits-boost-...
本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lambda表达式, function对象和bind机制。之所以把这三块放在一起讲,是因为这三块之间有着非常密切的关系,通过对比学习,加深对这部分内容的理解。在开始之间...
boost(> = 1.42,boost-system,boost-filesystem,boost-program_options,boost-asio,boost-bind,boost-pool) libcrypto ++ Qt(> = 5.5,使用QtQuick2,QML) 和cmake(> = 2.8) 安装 $ git clone sockc $ ...
boost::bind(&Foo::bar, boost::ref( *this ), ...) 如您所知, boost::bind可以使用成员函数的引用和指针,因此可以将所有此类调用简化为 boost::bind(&Foo::bar, this, ...) 我们不希望盲目搜索和替换boost::ref
你好,世界Hello World 演示测试项目结构体 CB { typedef boost::variant< boost> , boost::function<void> > ...< str> f( boost::bind( &CB::fun2, this, _1 ) );callback_["A"] = f ; boost::get< boost> >(callbac
auto grep_error = std::bind(grep, "Error.*", _1, _2); (boost::pipeline::from(input) | trim | grep_error | [] (const std::string& item) { return "-> " + item; } | output ).run(pool); 反馈 尽管该库...