mem_fun和bind1st

研究了一下mem_fun和bind1st,bind2st区别


代码如下,随后解释:

class A
{
public:
	bool f(int i)
	{
		return i == 20;
	}
};
int main()
{
	vector<int> v;
	v.push_back(10);
	v.push_back(20);
	v.push_back(30);
	A a;
	int c = count_if(v.begin(), v.end(), bind1st(mem_fun(&A::f), &a));
//    struct genterateFun
//    {
//        FuncPtr f
//        genterateFun(Function _f):f(_f){}
//        type operator()(A* pA,int x)
//        {
//            return pA->f(x);
//        }
//    };
//  assume the input parameter from vector is P
//  bind1st(F,Y) ==>// return a functor operator() will call genterateFunc(Y,P) cout << c << endl; // 1
    return 0;
}



   

你可能感兴趣的:(mem_fun和bind1st)