C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Algorithm transform()C++ Algorithm transform() function is used in two different ways: 1.unary operation:- This method performs unary operation op on the elements in range [first1, last1] and stores the result in range starting from result. This transform() applies a function to each element of a range: 2.Binary operation:- This method performs binary operation binary_op on the elements in range [first1, last1] with the elements in the range starting with iterator first2 and stores the result in range starting from result. This transform() takes two 2 ranges and applies a function that takes 2 parameters, on each couple of elements from the input ranges: Syntaxunary operation(1) template <class InputIterator, class OutputIterator, class UnaryOperation> OutputIterator transform (InputIterator first1, InputIterator last1, OutputIterator result, UnaryOperation op); Binary operation(2) template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation> OutputIterator transform (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryOperation binary_op); Parameterfirst1: An input iterator pointing the position of the first element of the first range to be operated on. last1: An iterator pointing the position one past the final element of the first range to be operated on. first2: Input iterator pointing to the first element in the second range to be operated on. result: An output iterator to the initial position of the range where the operation results are stored. op: Unary function applied to each element of the range. binary_op: Binary function that two elements passed as its arguments. Return valuetransform() returns an iterator pointing to the end of the transformed range. |