今天总算是弄明白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