当前位置: 首页 > news >正文

网站如何改版winserver2008上用iis发布网站

网站如何改版,winserver2008上用iis发布网站,套做网站,网站建设如何来选择空间好的&#xff0c;我会帮你详细介绍 C <numeric> 库 及其常用函数&#xff0c;并附带示例代码&#xff0c;方便理解。 以下内容会涵盖 <numeric> 的主要功能、常用函数、适用场景以及注意事项。1. <numeric> 库简介 <numeric> 是 C 标准库中的一个头文件…

好的,我会帮你详细介绍 C++ <numeric> 及其常用函数,并附带示例代码,方便理解。
以下内容会涵盖 <numeric> 的主要功能、常用函数、适用场景以及注意事项。


1. <numeric> 库简介

<numeric> 是 C++ 标准库中的一个头文件,主要提供了一些 数值运算工具函数,用来对序列(通常是容器中的元素)进行累加、相邻差值计算、内积、序列生成等操作。

常用特性:

  • 工作对象:任何支持迭代器(尤其是输入迭代器)的序列,例如 std::vectorstd::array、原生数组等。
  • 泛型:可以作用于任意类型(只要它们支持相应的运算符,比如 +、-、* 等)。

2. 常用函数总览

函数作用头文件
std::accumulate对范围内的元素进行累加或自定义的二元操作<numeric>
std::reduce (C++17)类似 accumulate,但可并行实现(需 <execution> 支持)<numeric>
std::inner_product计算两个序列的内积(可自定义加法和乘法运算)<numeric>
std::adjacent_difference计算相邻元素的差值(或自定义二元操作)<numeric>
std::partial_sum计算部分和(或自定义二元操作)<numeric>
std::inclusive_scan / exclusive_scan (C++17)类似 partial_sum,但有更多控制和并行支持<numeric>
std::iota从一个初始值开始,为范围内的元素按递增填充值<numeric>

3. 常用函数详解

3.1 std::accumulate

功能: 对一个迭代器范围内的元素求和,或用自定义函数进行累积。

语法:

template<class InputIt, class T>
T accumulate(InputIt first, InputIt last, T init);template<class InputIt, class T, class BinaryOperation>
T accumulate(InputIt first, InputIt last, T init, BinaryOperation op);

示例:

#include <iostream>
#include <vector>
#include <numeric> // accumulateint main() {std::vector<int> v = {1, 2, 3, 4, 5};int sum = std::accumulate(v.begin(), v.end(), 0);std::cout << "Sum: " << sum << "\n";// 计算乘积int product = std::accumulate(v.begin(), v.end(), 1, std::multiplies<>());std::cout << "Product: " << product << "\n";
}

输出:

Sum: 15
Product: 120

3.2 std::inner_product

功能: 计算两个序列的内积,可以自定义加法和乘法运算。

语法:

template<class InputIt1, class InputIt2, class T>
T inner_product(InputIt1 first1, InputIt1 last1,InputIt2 first2, T init);template<class InputIt1, class InputIt2, class T,class BinaryOperation1, class BinaryOperation2>
T inner_product(InputIt1 first1, InputIt1 last1,InputIt2 first2, T init,BinaryOperation1 op1, BinaryOperation2 op2);

示例:

#include <iostream>
#include <vector>
#include <numeric> // inner_productint main() {std::vector<int> a = {1, 2, 3};std::vector<int> b = {4, 5, 6};int result = std::inner_product(a.begin(), a.end(), b.begin(), 0);std::cout << "Inner product: " << result << "\n"; // 32// 使用自定义操作(这里是 a[i]-b[i] 的和)int diff_sum = std::inner_product(a.begin(), a.end(), b.begin(), 0,std::plus<>{}, std::minus<>{});std::cout << "Sum of differences: " << diff_sum << "\n"; // -9
}

3.3 std::adjacent_difference

功能: 生成一个新序列,每个元素为输入序列中相邻两个元素的差值(可自定义二元运算)。

语法:

template<class InputIt, class OutputIt>
OutputIt adjacent_difference(InputIt first, InputIt last, OutputIt d_first);template<class InputIt, class OutputIt, class BinaryOperation>
OutputIt adjacent_difference(InputIt first, InputIt last, OutputIt d_first, BinaryOperation op);

示例:

#include <iostream>
#include <vector>
#include <numeric> // adjacent_differenceint main() {std::vector<int> v = {1, 3, 6, 10, 15};std::vector<int> result(v.size());std::adjacent_difference(v.begin(), v.end(), result.begin());for (int n : result) std::cout << n << " "; // 1 2 3 4 5
}

3.4 std::partial_sum

功能: 生成部分和序列(可自定义二元运算)。

语法:

template<class InputIt, class OutputIt>
OutputIt partial_sum(InputIt first, InputIt last, OutputIt d_first);template<class InputIt, class OutputIt, class BinaryOperation>
OutputIt partial_sum(InputIt first, InputIt last, OutputIt d_first, BinaryOperation op);

示例:

#include <iostream>
#include <vector>
#include <numeric> // partial_sumint main() {std::vector<int> v = {1, 2, 3, 4, 5};std::vector<int> result(v.size());std::partial_sum(v.begin(), v.end(), result.begin());for (int n : result) std::cout << n << " "; // 1 3 6 10 15
}

3.5 std::iota

功能: 填充一个范围,从某个初始值开始递增。

语法:

template<class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value);

示例:

#include <iostream>
#include <vector>
#include <numeric> // iotaint main() {std::vector<int> v(5);std::iota(v.begin(), v.end(), 10); // 从 10 开始for (int n : v) std::cout << n << " "; // 10 11 12 13 14
}

4. 使用建议与注意事项

  1. 当使用浮点数时,累加运算可能会有 精度误差(特别是大规模数据)。
  2. 对于需要高性能的并行数值计算,可以使用 std::reducestd::transform_reduce(C++17+)。
  3. 这些算法可以搭配 标准函数对象(如 std::plus<>std::multiplies<>)或 lambda函数,灵活性很高。
  4. <numeric> 函数不会修改原序列,除非明确要求将结果输出到同一位置(如 partial_sum)。
http://www.dtcms.com/a/551770.html

相关文章:

  • 网站建设肆金手指排名4太原建设网站公司
  • 微信公众平台网站建设wordpress 示例页面
  • 阿里巴巴网站是怎么做的网站建设对信息公开的作用
  • 建个网站需要多少钱网络推广是什么职位
  • 洛阳 网站建设 大师字画简易网站建设维护
  • 网站开发工程师职业网站怎样做域名绑定
  • 制作微网站多少钱衡水网站建设最新报价
  • 维护网站费用怎么做会计凭证农村电商平台网站设计思路有哪些
  • 职业学校网站模板做rom网站
  • 怎样创建网站微信官方登录入口
  • 旅游景点网站策划书农庄网站模板
  • 网站设计如何开始河北中石化建设网站
  • 广州seo网站推广平台自助建站免费建站平台
  • 做cps要做什么类型的网站楚雄百度推广电话
  • 做好系部宣传和网站建设杭州微网站建设公司
  • 设计本装修效果图杭州网站建设seo
  • 响水网站设计成都区块链网站开发
  • 电子商务网站建设如何策划与实施江门建站价格
  • 建设英文网站费用网站建设模板源码
  • 网站建设效果图淄博专业网站建设价格
  • 2018年公司网站建设费分录hao123网址怎么删除
  • 网站设计登录界面怎么做网站规划小结
  • 做网站制作需要多少钱石家庄模板自助建站
  • wap网站html模板网络规划设计师教程(第2版) 严体华 pdf
  • 做海外网站推广响应式网站建站工具
  • 网站建设缺陷网站安全设置教程
  • 营销网站制作都选ls15227企业网站管理系统手机版教程
  • 什么网站可以做字体效果好网站建设好后有些什么资料
  • wordpress建站配置深圳sem优化
  • 未来做那个网站致富多说 wordpress