STL中的ptr_fun
来源:互联网 发布:linux开机自启动ssh 编辑:程序博客网 时间:2024/05/21 20:25
STL中的ptr_fun
ptr_fun只是将一个普通的函数(或者函数指针)适配成类pointer_to_binary_function,而该类实际上是binary_function的子类,这样出来的functor就有利于同STL的算法等适配。
下面的例子就是说明了使用ptr_fun将普通的函数适配成bind1st或bind2nd能够使用的functor,否则对bind1st或bind2nd直接绑定普通函数,则编译出错。
下面的例子就是说明了使用ptr_fun将普通的函数适配成bind1st或bind2nd能够使用的functor,否则对bind1st或bind2nd直接绑定普通函数,则编译出错。
#include <algorithm>#include <functional>#include <iostream>using namespace std;int sum(int arg1, int arg2){cout<<"ARG 1: "<<arg1<<endl;cout<<"ARG 2: "<<arg2<<endl;int sum = arg1 + arg2;cout<<"SUM: "<<sum<<endl;return sum;}int main(int argc,char* argv[]){bind1st(ptr_fun(sum),1)(2); // the same as sum(1,2)bind2nd(ptr_fun(sum),1)(2); //the same as sum(2,1)getchar();return 0;}
运行结果:
- STL中的ptr_fun
- stl中functional中的ptr_fun和pointer_to_binary_function
- 【STL】ptr_fun详解
- ptr_fun
- ptr_fun
- ptr_fun
- STL示例08(ptr_fun和random_shuffle搭配使用)
- 关于标准库中的ptr_fun/binary_function/bind1st/bind2nd
- 关于标准库中的ptr_fun/binary_function/bind1st/bind2nd
- 关于标准库中的ptr_fun/binary_function/bind1st/bind2nd
- 了解使用ptr_fun、mem_fun和mem_fun_ref的原因1(Effective stl 条款41)
- 了解使用ptr_fun、mem_fun和mem_fun_ref的原因2(Effective stl 条款41)
- 了解使用ptr_fun、mem_fun和mem_fun_ref的原因3(Effective stl 条款41)
- effective stl 第41条:理解ptr_fun/mem_fun/mem_fun_ref的由来
- Effective STL 41 Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref
- ptr_fun详解
- ptr_fun详解
- ptr_fun,mem_fun,mem_fun_ref 浅析
- 存储过程
- erializable java序列化
- QT paintevent 事件, update()槽函数
- linux shell笔记
- 老码农教你学英语:补充一些英语学习素材
- STL中的ptr_fun
- 男人应该掌握的100项技能
- RESTFUL Service : based on Jersey
- SharePoint Designer2010 设计多级审批工作流。
- 数组
- Run.vbs
- js中新建添加窗口位置设置
- 100个英语超精简口语短句
- 中小型软件项目开发一般流程