transform_inclusive_scan() is inbuilt function in C++ and its same as inclusive_scan(), except a unary function which is first applied to each input item.
Its functionality is to transform each and every element between first and last with unary_op then computes an inclusive prefix sum operation by the help of binary_op with a specific range. An inclusive defined the i-th input element is included in the i-th sum operation.
We can take an optional init(initial values)and writes the results to the range beginning at d_first.
template < class InputItrator, class OutputItrator, class BinaryOperation, class UnaryOperation > OutputItrator transform_inclusive_scan( InputItrator first, InputItrator last, OutputItrator d_first, BinaryOperation binary_op, UnaryOperation unary_op );
- first and last:-The first and last elements define the range of an elements sum .
- d_first:-Its beginning of the destination range .
- unary_op:-Operation to be appliied on each element in the input range.
- binary_op:-Operation to be applied to the result of unary_op and the results of other binary_op, and if init(initial val ) will be provided.
- InputItrator: The Inputiterator is class of an Iterator and its able to read from the pointed to element.If once i has incremented then all others copies are invalidated and its validity for single pass algorithm.
- OutputItrator: The OutputIterator is an Iterator that can be written to the pointed element.
Return Values: An iterator to the element past the last element written.
Note: An unary_op is optional in this function and not applied to init. Actually, the init parameter appears at last.
Following is the implementation of above problem.
121 605 1694 3630 6655 11011 16940 24684
Note: Above program may not run on many IDE’s.