取反适配器


#include
#include
#include
#include
using namespace std;
//取反适配器
//not2二元取反适配器

struct Compare :public binary_function<int,int,bool>
{
    bool operator()(int a,int b)const
    {
        return a > b;
    }
};

struct Output
{
    void operator()(int v)
    {
        cout << v << endl;
    }
};
int main()
{
    vector<int> v;
    for (int i = 0; i < 5; i++)
    {
        v.push_back(rand() % 100);
    }
    sort(v.begin(), v.end(), Compare());
    for_each(v.begin(), v.end(), Output());

    //去反适配器
    sort(v.begin(), v.end(), not2(Compare()));
    for_each(v.begin(), v.end(), Output());
}