取反适配器

#include

//取反适配器--一元取反

#include

using namespace std;

class GreatThanFive:public unary_function{//继承

public:

    bool operator()(int value) const

    {

        return  value > 5;

    }

};

int main()

{

    vector v;

    for(int i = 0; i < 10;i++){

        v.push_back(i);

    }

    vector::iterator pos= find_if(v.begin(),v.end(),not1(GreatThanFive()));//not1 一元取反

    if(pos != v.end()){

        cout<<"小于5的数是"<<*pos<

    }else {

        cout<<"小于5的数未找到"<

    }

    return 0;

}


你可能感兴趣的:(取反适配器)