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

std::exclusive_scan

Defined in header <numeric>

?

?

template< class InputIt, class OutputIt, class T > OutputIt exclusive_scan( InputIt first, InputIt last, OutputIt d_first, T init );

(1)

(since C++17)

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

(2)

(since C++17)

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

(3)

(since C++17)

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

(4)

(since C++17)

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

形式上,通过每个迭代器分配i在。[丁[医]第一,d[医]第一+%28最后-第一%29%29广义非交换和的值init, *j...为每一个j在。[第一,第一+%28i-d[医]第一%29%29以上binary_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%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

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.

类型要求

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

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

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

-T必须符合可移动建筑的要求。和二进制[医]执行部分第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_exclusive_scan (C++17)

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

inclusive_scan (C++17)

similar to std::partial_sum, includes the ith input element in the ith sum (function template)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com