首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::inclusive_scan

Defined in header <numeric>

?

?

template< class InputIt, class OutputIt > OutputIt inclusive_scan( InputIt first, InputIt last, OutputIt d_first );

(1)

(since C++17)

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2 > ForwardtIt2 inclusive_scan( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first );

(2)

(since C++17)

template< class InputIt, class OutputIt, class BinaryOperation > OutputIt inclusive_scan( InputIt first, InputIt last, OutputIt d_first, BinaryOperation binary_op );

(3)

(since C++17)

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryOperation > ForwardIt2 inclusive_scan( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, BinaryOperation binary_op );

(4)

(since C++17)

template< class InputIt, class OutputIt, class BinaryOperation, class T > OutputIt inclusive_scan( InputIt first, InputIt last, OutputIt d_first, BinaryOperation binary_op, T init );

(5)

(since C++17)

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class BinaryOperation, class T > ForwardIt2 inclusive_scan( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, BinaryOperation binary_op, T init );

(6)

(since C++17)

使用binary_op%28或std::plus<>()对于过载%281-2%29%29的范围[first, last),使用init作为初始值%28(如果提供了%29),并将结果写入从d_first“包含”是指I-th输入元素包含在I-th和中。

形式上,通过每个迭代器分配i在。[丁[医]第一,d[医]第一+%28最后-第一%29%29的值为:

  • 对于过载%281-4%29,广义非交换和*j...为每一个j在。[第一,第一+%28i-d[医]第一+1%29%29binary_op
  • 对于过载%285-6%29,广义非交换和init, *j...为每一个j在。[第一,第一+%28i-d[医]第一+1%29%29binary_op

其中广义非交换和GNSUM%28op,a

1,...a

N%29的定义如下:

  • 如果N=1,a 一
  • 如果N>1,OP%28 GNSUM%28 OP,a

1,...a

K%29,GNSUM%28,a

M,...,a

n%29%29对于任意K,其中1<K+1=M≤N

换句话说,求和操作可以按任意顺序执行,并且在以下情况下行为是不确定的。binary_op不是联想的。

重载%282,4,6%29根据policy。此重载只参与以下情况下的过载解决方案:std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的。

binary_op不应使迭代器%28(包括结束迭代器%29或子范围)无效,也不应修改范围中的元素。[首先,最后%29或。[丁[医]第一,d[医]第一+%28最后-第一%29%29。否则,行为就没有定义。

参数

first, last

-

the range of elements to sum

d_first

-

the beginning of the destination range; may be equal to first

policy

-

the execution policy to use. See execution policy for details.

init

-

the initial value (optional)

binary_op

-

binary FunctionObject that will be applied in to the result of dereferencing the input iterators, the results of other binary_op, and init (if provided).

类型要求

-输入必须符合输入器的要求。

-输出必须符合输出器的要求。

-前进1必须符合先行者的要求。如果没有提供init,则将其1%27s值[医]类型必须是可移动的和二进制的[医]执行部分第28段%2A首先,%2A第一%29必须转换为前进It 1%27s值类型

-前进2必须符合先行者的要求。

-T%28,如果提供了%29必须符合可移动建筑的要求。全部二进制[医]执行部分第28段,%2A第29%,二进制[医]OP%28 init、init%29和二进制[医]执行部分第28段%2A首先,%2A第29%必须转换为T

返回值

Iterator到元素的最后一个写成的元素。

复杂性

O%28最后-第一%29应用程序的二进制操作。

例外

带有名为ExecutionPolicy报告错误如下:

  • 如果执行作为算法一部分调用的函数,则引发异常ExecutionPolicy是其中之一标准政策,,,std::terminate叫做。对于任何其他人ExecutionPolicy,行为是由实现定义的。
  • 如果算法不能分配内存,std::bad_alloc被扔了。

另见

adjacent_difference

computes the differences between adjacent elements in a range (function template)

accumulate

sums up a range of elements (function template)

partial_sum

computes the partial sum of a range of elements (function template)

transform_inclusive_scan (C++17)

applies a functor, then calculates inclusive scan (function template)

exclusive_scan (C++17)

similar to std::partial_sum, excludes the ith input element from the ith sum (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com