算法之旅,直奔<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; }
相关文章推荐
- 算法之旅,直奔<algorithm>之一 all_of
- 算法之旅,直奔<algorithm>之十七 find_first_of
- 算法之旅,直奔<algorithm>之三 any_of
- 算法之旅,直奔<algorithm>之十七 find_first_of
- 算法之旅,直奔<algorithm>之十三 fill
- 算法之旅,直奔<algorithm>之八 copy_n
- 算法之旅,直奔<algorithm>之十二 equal_range
- 算法之旅,直奔<algorithm>之十四 fill_n
- 算法之旅,直奔<algorithm>之十六 find_end
- 算法之旅,直奔<algorithm>之九 count
- 算法之旅,直奔<algorithm>之十 count_if
- 算法之旅,直奔<algorithm>之十三 fill
- 算法之旅,直奔<algorithm>之二十一 max
- 算法之旅,直奔<algorithm>之六 copy_backward
- 算法之旅,直奔<algorithm>之十一 equal
- 算法之旅,直奔<algorithm>之二十二 sort
- 算法之旅,直奔<bitset>之六 none
- 算法之旅,直奔<algorithm>之二 adjacent_find
- 算法之旅,直奔<algorithm>之十五 find
- 算法之旅,直奔<algorithm>之二十 make_heap