STL示例09(绑定器bind1st)

来源:互联网 发布:淘宝号码 编辑:程序博客网 时间:2024/06/05 22:54
//STL示例 绑定器函数对象bind1st#include <iostream>#include <algorithm>#include <functional>#include <list>using namespace std;int iarray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};list<int> aList(iarray, iarray + 10);int main(){int k = 0;//count_if统计满足条件的元素个数/*其中greater()实现如下template<class T>    struct greater : public binary_function<T, T, bool> {    bool operator()(const T& x, const T& y) const {return (x>y);};    };bind1st函数作用是将8绑定到greater的第一个参数上,看上面greater类型定义及实现可以知道这里是求小于8的元素*/k=count_if(aList.begin(), aList.end(),bind1st(greater<int>(),8));cout << "小于8的数的个数 :" << k << endl;return 0;}

原创粉丝点击