预定义函数对象
来源:互联网 发布:秋季淘宝网什么好卖 编辑:程序博客网 时间:2024/05/01 16:02
#include <iostream> #include<string> #include <vector> #include <list> #include <set> #include <map> #include <algorithm> #include <functional> using namespace std; //plus 预定义函数对象 能实现不能类型数据的+运算// 实现了算法和数据类型的分离 ===》通过函数对象技术实现的/*template<class _Ty>struct plus: public binary_function<_Ty, _Ty, _Ty>{// functor for operator+_Ty operator()(const _Ty& _Left, const _Ty& _Right) const{// apply operator+ to operandsreturn (_Left + _Right);}};*/void display(){plus<int> intadd;int x = 10l;int y = 200;int z = intadd(x,y);cout<<z<<endl;plus<string> stringadd;string s1 = "aaaa";string s2 = "bbbb";string s3 = stringadd(s1,s2);cout<<s3<<endl;cout<<"---------------"<<endl;/*template<class _RanIt,class _Pr> inlinevoid sort(_RanIt _First, _RanIt _Last, _Pr _Pred){// order [_First, _Last), using _Pred_DEBUG_RANGE(_First, _Last);_DEBUG_POINTER(_Pred);_Sort(_Unchecked(_First), _Unchecked(_Last), _Last - _First, _Pred);}*/vector<string> v;v.push_back("dddd");v.push_back("aaaa");v.push_back("cccc");v.push_back("cccc");v.push_back("bbbb");sort(v.begin(),v.end(),greater<string>());for (vector<string>::iterator it = v.begin();it!=v.end();it++){cout<<*it<<endl;}//统计和字符串相等的个数//equal_to<string> 有两个参数 left参数来自容器,right参数来自sc;//bind2nd函数适配器 把预定义函数对象和第二个参数进行绑定string sc = "cccc";int num = count_if(v.begin(),v.end(),bind2nd(equal_to<string>(),sc));cout<<num<<endl;}int main(){display();system("pause");return 0;}
0 0
- 预定义函数对象
- 预定义函数对象和函数适配器案例
- STL函数对象之预定义函数对象和函数对象绑定器
- STL算法设计理念 - 预定义函数对象
- 常用预定义函数
- Geogebra预定义函数
- stl算法设计理念_预定义函数对象和函数适配器1
- stl算法设计理念_预定义函数对象和函数适配器2_案例
- javascript中的预定义函数
- JavaScript的预定义函数
- Linux--预定义变量、函数
- 十、STL函数对象---预定义的Function object 和Binder
- 如何访问预定义的GDI对象
- ActionScript系统预定义对象详解
- 如何访问预定义的GDI对象
- Hive的预定义UDF函数
- Hive的预定义UDF函数
- Hive的预定义UDF函数
- CentOS下yum安装php-memcached
- 深入 Java 内存模型(2)
- 顺序队列模板--c++实现
- 兄弟郊游问题
- Solr6.2.1集群搭建
- 预定义函数对象
- 第一型曲线积分的思路总结
- Barclays交易平台分析(FLASH逆向分析)
- ListView之ImageLoader实现图片加载
- go 生成的exe不在bin文件夹里
- json-lib及其使用的jar包
- String,StringBuffer与StringBuilder的区别??
- UML—行为图(状态图、活动图)
- Vijos P1494 杨辉三角形中的偶数个数