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

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>库的示例代码。其中引用是一个使用fill函数将a的所有元素填充为957的例子。引用是一个将数组a的部分元素进行倒序排列的例子。引用是一个使用next_permutation函数生成数组a所有元素的全排列的例子。 在C++中,<algorithm>是一个标准库,提供了一些常用的算法和函数,用于操作序列(如数组和容器)的元素。这些算法包括排序、查找、计数、操作顺序等。通过包含<algorithm>头文件,我们可以使用这些算法来简化程序的开发和实现。 所以,当我们在C++程序中使用#include<algorithm>时,我们可以调用<algorithm>库中的函数来实现各种操作,例如对序列进行排序、查找、计数等。这样可以提高程序的效率和可读性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [#include<algorithm>中常用函数的使用](https://blog.youkuaiyun.com/brilliantZC/article/details/105545282)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [C++头文件 <algorithm>的 常用函数(详细)](https://blog.youkuaiyun.com/Rock_Lihaoran/article/details/122753704)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值