bind1st 和 bind2nd的区别

来源:互联网 发布:vr源码 编辑:程序博客网 时间:2024/05/17 22:23

今天总算是弄明白bind1st和bind2nd是怎么用的,有什么区别了。只知道工作,不知道学习很久了。

 

// bind1st example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main () {
  int numbers[] = {10,20,30,40,50,10};
  int cx;
  cx = count_if (numbers, numbers+6, bind1st(greater<int>(),10) );
  cout << "There are " << cx << " elements that are equal to 10.\n";
  return 0;
}

// bind2nd example
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int main () {
  int numbers[] = {10,20,30,40,50,10};
  int cx;
  cx = count_if (numbers, numbers+6, bind2nd(greater<int>(),10) );
  cout << "There are " << cx << " elements that are equal to 10.\n";
  return 0;
}

 

Reference:

http://stackoverflow.com/questions/6112573/bind1st-and-bind2nd

http://stackoverflow.com/questions/6863677/use-bind1st-or-bind2nd

http://www.cplusplus.com/reference/functional/bind1st/

http://www.cplusplus.com/reference/functional/bind2nd/

原创粉丝点击