bind1st,bind2nd,not1,not2

来源:互联网 发布:投稿被怀疑数据造假 编辑:程序博客网 时间:2024/05/20 00:49

bind1st和bind2nd函数用于将一个二元算子(binary functor,bf)转换成一元算子(unary functor,uf)

// 移除所有小于100的元素
arr.erase( std::remove_if( arr.begin(),  arr.end(),
    std::bind2nd( std::less< int>(), 100)), arr.end());

// 移除所有大于100的元素
arr.erase( std::remove_if( arr.begin(),  arr.end(),
    std::bind1st( std::less< int>(), 100)), arr.end());

// 移除所有大于100的元素
arr.erase( std::remove_if( arr.begin(),  arr.end(),
    std::bind2nd( std::greater< int>(), 100)), arr.end());

// 移除所有小于等于100的元素
arr.erase( std::remove_if( arr.begin(),  arr.end(),
    std::not1(std::bind2nd( std::greater< int>(), 100))), arr.end());

not1()和not2()

not1()接受单目函数对象,not2()接受双目函数对象

 

参考资料:http://blog.csdn.net/lalor/article/details/7975621

http://blog.163.com/liuruigong_lrg/blog/static/2737030620080295843330/

 

0 0