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.
- Function Overloading vs Function Overriding in C++
- How to call some function before main() function in C++?
- Difference between Virtual function and Pure virtual function in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- log() function in C++
- exp() function C++
- fma() function in C++
- div() function in C++
- mbsrtowcs() function in C/C++
- isunordered() function in C++
- mbsinit() Function in C/C++
- bit_and function in C++
- mbrlen() function in C/C++
- wcspbrk() function in C/C++
- wcsrchr() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.