您的位置:首页 > 编程语言 > Go语言

算法之旅,直奔<algorithm>之二十三 none_of

2013-12-22 22:14 555 查看

none_of(vs2010)


引言
这是我学习总结<algorithm>的第二十三篇,none_of 可以和all_of,any_of等一起学习的。那样特好理解。喜欢跳舞么?让我们代码去舞吧。
作用
none_of 的作用是检测所有的数据是否都符合某个条件或者都不符合某个条件,那就看你怎么用了。
原型
template<class InputIterator, class UnaryPredicate>
InputIterator none_of (InputIterator first, InputIterator last, UnaryPredicate pred)
{
while (first!=last) {
if (pred(*first)) return false;
++first;
}
return true;
}

实验
         


代码
test.cpp
#include <iostream>     // std::cout
#include <algorithm>    // std::none_of
#include <array>        // std::array
#include <iterator>

int main () {
std::array<int,8> foo = {1,2,4,8,16,32,64,128};
std::copy(foo.begin(),foo.end(),std::ostream_iterator<int>(std::cout," "));
std::cout<<std::endl<<"检测是否含有负数"<<std::endl;
if ( std::none_of(foo.begin(), foo.end(), [](int i){return i<0;}) )
std::cout << "There are no negative elements in the range.\n";
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ algorithm vs2010