取反适配器

2019-10-30  本文已影响0人  python小青

#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<<endl;

    }else {

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

    }

    return 0;

}

上一篇 下一篇

猜你喜欢

热点阅读