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

std::transform_inclusive_scan

Defined in header <numeric>

?

?

template< class InputIt, class OutputIt, class BinaryOperation, class UnaryOperation > OutputIt transform_inclusive_scan( InputIt first, InputIt last, OutputIt d_first, BinaryOperation binary_op, UnaryOperation unary_op );

(1)

(since C++17)

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

(2)

(since C++17)

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

(3)

(since C++17)

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

(4)

(since C++17)

转换范围内的每个元素。[first, last)带着unary_op,然后使用binary_op在结果范围内,可以选择使用init作为初始值,并将结果写入从d_first“包含”是指I-th输入元素包含在I-th和中。

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

  • 对于过载%281-2%29,广义非交换和unary_op(*j)...为每一个j在。[第一,第一+%28i-d[医]第一+1%29%29binary_op,,,
  • 对于过载%283-4%29,广义非交换和init, unary_op(*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%29根据policy,并且不参与过载解决,除非std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的。

unary_opbinary_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

unary_op

-

unary FunctionObject that will be applied to each element of the input range. The return type must be acceptable as input to binary_op.

binary_op

-

binary FunctionObject that will be applied in to the result of unary_op, the results of other binary_op, and init if provided.

类型要求

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

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

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

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

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

返回值

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

复杂性

O%28最后---每一份申请的首%29份binary_opunary_op...

例外

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

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

注记

unary_op不适用于init...

参数init最后出现,与std::transform_exclusive_scan,因为它对于这个函数是可选的。

另见

partial_sum

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

transform

applies a function to a range of elements (function template)

inclusive_scan (C++17)

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

transform_exclusive_scan (C++17)

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

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com