STL - 仿函数

bool func1(int a)
{
    return a < 5;
}

struct func2: public unary_function<int, bool>
{
    bool operator()(int a)
    {
        return a < 5;
    }
};

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

int main(int argc, char* argv[])
{
    list<int> int_list;
    int_list.remove_if(func1);
    int_list.remove_if(func2());
    int_list.remove_if(bind1st(greater<int>(), 5));
    int_list.remove_if(bind2nd(less<int>(), 5));
    int_list.remove_if([](int& a){
        return a < 5;
    });
}

 

posted @ 2013-05-12 16:11  Leung文  阅读(126)  评论(0编辑  收藏  举报