STL bind1st bind2nd详解
来源:互联网 发布:视频下载王 mac 编辑:程序博客网 时间:2024/05/18 13:30
先不要被吓到,其实这两个配接器很简单。
首先,他们都在头文件<functional>中定义。
其次,bind就是绑定的意思,而1st就代表first,2nd就代表second,现在名在可以很快记住了。
再次,他们的申明是一样的,都是(const Operation& op, const T& x)。
简单的说,bind1st(const Operation& op, const T& x)就是这么一个操作:x op value,而bind2nd(const Operation& op, const T& x)就是这么一个操作:value op x,其中value是被应用bind的对象。这两个配接器都用于将一个二元算子转换成一个一元算子。下面来看一段代码吧!
//Coded by www.programlife.net#include <iostream>#include <functional>#include <algorithm>#include <vector>using namespace std;int main(){vector<int> coll;for(int i = 1; i <= 10; ++i){coll.push_back(i);}//查找元素值大于10的元素的个数//也就是使得10 < elem成立的元素个数int res = count_if(coll.begin(), coll.end(), bind1st(less<int>(), 10));cout << res << endl;//查找元素值小于10的元素的个数//也就是使得elem < 10成立的元素个数res = count_if(coll.begin(), coll.end(), bind2nd(less<int>(), 10));cout << res << endl;return 0;}
程序的输出结果是0 9
http://www.programlife.net/stl-bind1st-bind2nd-demo.html
- STL bind1st bind2nd详解
- STL bind1st bind2nd详解
- bind1st bind2nd详解
- stl 中bind1st和bind2nd
- STL中bind1st和bind2nd的区别
- stl之bind1st,bind2nd解读(转)
- 【STL】bind1st与bind2nd函数解析
- STL binder1st binder2nd bind1st bind2nd区别
- STL bind1st、bind2nd的使用【转】
- STL中bind1st和bind2nd之解析
- STL: bind1st, bind2nd 的使用(C++)
- 【STL】bind1st与bind2nd函数解析
- bind1st & bind2nd
- not1,not2,bind1st和bind2nd详解
- STL的bind1st,bind2nd,mem_fun,mem_fun_ref使用示例
- 【STL】函数 for_each; bind1st和bind2nd,not1; mem_fun和mem_fun_ref;
- bind1st bind2nd的使用
- 引用 bind1st bind2nd
- c# 2.0实现摄象头视频采集,拍照,录象
- C#中打开Excel并刷新加载宏的方法
- 关于在Linux服务器上建立新用户
- Java程序员从笨鸟到菜鸟之(五十二)细谈Hibernate(三)Hibernate常用API详解及源码分析
- IPhone开源代码汇总
- STL bind1st bind2nd详解
- 高效程序员的 7 个共同特征
- haskell(15)
- poj2635-大进制转化+同余定理+素数筛选
- Installing CUDA Toolkit 5.0 on CentOS 6.4
- ANT简明教程
- Android 下拉刷新控件之ScrollView版本实现
- The APR based Apache Tomcat Native library
- pptp