一:功能
计算相邻两个元素的差(默认),也可以使用其他自定义运算函数,比如计算相邻两个元素的和。
二:用法
#include <iostream>
#include <vector>
#include <numeric>
int main() {
std::vector<int> data{2, 3, 5, 7, 11, 13};
//前两个参数指定输入的范围,第三个参数是指定输出的位置
std::adjacent_difference(data.begin(), data.end(), data.begin());
for (auto v : data)
std::cout << v << " ";
std::cout << "\n";
}
//2 1 2 2 4 2
//并行版本
#include <iostream>
#include <vector>
#include <numeric>
#include <execution>
int main() {
std::vector<int> data{2, 3, 5, 7, 11, 13};
std::vector<int> out(data.size());
std::adjacent_difference(std::execution::par_unseq,
data.begin(), data.end(), out.begin());
for (auto v : out)
std::cout << v << " ";
std::cout << "\n";
}
//2 1 2 2 4 2
标签:std,begin,include,STL,adjacent,difference,data,out From: https://blog.csdn.net/zg260/article/details/140835001