1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "stdafx.h"
using namespace std;
int main(int argc, char **argv)
{
vector<int> v;
int result = 0;
int myArray[5] = { 1, 2, 3, 4, 5} ;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(-20);
binder2nd<less<int>() > functionObj = bind2nd(less<int>(),3);
count_if(v.begin(),v.end(), functionObj, result);
cout << result << endl;
result = 0;
count_if(myArray,&myArray[5],functionObj,result);
cout << result << endl;
result = 0;
count_if(myArray,&myArray[5],bind2nd(less<int>(), 5) ,result);
cout << result << endl;
result = 0;
count_if(v.begin(),v.end(),bind2nd(less<int>(), 5) ,result);
cout << result << endl;
return 0;
}
|