仿函数小例子
来源:互联网 发布:花都金蝶软件代理商 编辑:程序博客网 时间:2024/05/17 23:59
通过侯捷老师的视频学习了一些仿函数的使用,我只学了使用,其中主要模拟了pair的count和key的输出。并没有深入学习具体过程,在此贴上一位大佬的帖子链接(http://m.blog.csdn.net/yangquanhui1991/article/details/51721519)
#include<string>#include<map>#include<functional>template <class Pair>class select1st :public unary_function<Pair,typename Pair::first_type>{public: const typename Pair::first_type& operator()(const Pair&x) const{ return x.first; }};template<class Pair>struct select2ed :public unary_function<Pair, typename Pair::second_type> { const typename Pair::second_type& operator()(const Pair&x)const { return x.second; }};template<class T>class Equal_to :public binary_function<T, T, bool> {public: bool operator()(const T&x, const T&y)const { return x == y; }};int main(void) { Equal_to<int>Equal; cout << Equal(1, 1) << endl; pair<string, int>p("string",1); cout << select1st<pair<string, int>>()(p); cout << select2ed<pair<string, int>>()(p); system("pause"); return 0;}
阅读全文
0 0
- 仿函数小例子
- 仿通讯录ListView小例子
- [Android]仿通讯录ListView小例子
- [Android]仿通讯录ListView小例子
- Oracle 函数小例子
- 仿函数,即函数对象,的一个简单例子
- linux C时间函数应用小例子
- 结构体函数应用小例子typedef
- SQLServer 用户自定义函数小例子
- php构造函数的小例子
- 函数对象 及 简单的小例子
- Hive UDF自定义函数编写小例子
- LEAD分析函数用法小例子
- js 函数表达式-递归 小例子
- Oracle 常用函数以及小例子
- 实现大堆小堆——仿函数的应用
- 仿函数
- 仿函数
- smoj1987(cdq分治+离散化/数据结构)
- HDU2147 Brave Game (巴什博弈 )
- Code Composer Studio 7.3.0安装错误。
- Manthan, Codefest 17-E-Salazar Slytherin's Locket(数位DP)
- 八大排序算法
- 仿函数小例子
- 慕课网bootstrap一
- [POJ](2251)Dungeon Master ---三维bfs
- 机器学习中的Bias,Error,Variance的区别
- hdu 2489 Minimal Ratio Tree(prim+dfs)
- android Messenger跨进程通信
- Scroller实现View弹性滑动
- Android dp方式的屏幕适配工具使用(bat批处理方式)
- Java:HashMap、HashTable