C语言中scan的意义,C ++中的transform_inclusive_scan()函数

在本教程中,我们将讨论一个程序,以了解C ++中的transform_inclusive_scan()函数。

示例#include 

#include 

using namespace std;

namespace point_input_iterator {

template 

OutputItrator transform_inclusive_scan(InputItrator first,

InputItrator last,

OutputItrator d_first,

BinaryOperation binary_op,

UnaryOperation unary_op){

*d_first = unary_op(*first);

first++;

d_first++;

for (auto it = first; it != last; it++) {

//计算前缀和

*d_first = binary_op(unary_op(*it), *(d_first - 1));

d_first++;

}

return d_first;

}

}

int main(){

//使用vector输入元素

vector InputVector{ 11, 22, 33, 44, 55, 66, 77, 88 };

vector OutputVector(8);

point_input_iterator::transform_inclusive_scan(InputVector.begin(), InputVector.end(), OutputVector.begin(), [](auto xx, auto yy) {

return xx + yy;

},

[](auto xx) {

return xx * xx;

});

for (auto item : OutputVector) {

//打印输出项

cout <

}

cout <

return 0;

}

输出结果121 605 1694 3630 6655 11011 16940 24684

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值