成员函数适配器:将成员函数变成函数对象
mem_fun是使成员函数作为函数对象,传入对象指针。mem_fun_ref
使成员函数作为函数对象,传入对象引用。
普通函数适配器
普通函数适配器无"配接能力"
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
bool g(int x, int y)
{
return x>y;
}
int main()
{
int a[] = {2, 5, 3, 7, 1, 9, 8, 0, 6};
int nSize = sizeof(a)/sizeof(int);
int nCount = count_if(a, a+nSize, bind2nd(ptr_fun(g), 3));//这里不能写bind2nd(g, 3)
cout << nCount;
return 0;
}