STL binder1st binder2nd bind1st bind2nd区别

binder**和bind**功能对应。只是binder**是类绑定器,bind**为全局函数绑定器而已。

1st和2nd很好理解。一个是第一个参数不变,一个是第二个参数不变。

参看程序:

#include "stdafx.h"#include <iostream>#include <algorithm>// count_if#include <functional>// binder#include <list>using namespace std;int main(){// Dataint iarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};list<int> aList(iarray, iarray + 10);// binder和bind区别:// 1. 类绑定器有binder1st和binder2nd,而函数绑定器是bind1st和bind2nd// 2. bind是一个全局的模板函数其返回值为一个binder模板类的实例// 3. binder要指定泛型int k = count_if(aList.begin(), aList.end(), binder1st<greater<int>>(greater<int>(), 5));// bind1st bind2nd功能比较// k = count_if(aList.begin(), aList.end(), bind1st(greater<int>(), 5)); // bind1st(greater<int>(), 5); //—->5 > x 即5作为第一个固定参数。返回5大于的数字的个数// bind2nd(greater<int>(), 5); //—->x > 5 即5作为第二个固定参。返回大于5的数字的个数cout << k << endl;system("pause");return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,可就是这样,还是有人,期望过多的温暖。

STL binder1st binder2nd bind1st bind2nd区别

相关文章:

你感兴趣的文章:

标签云: