Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/algorithm/transform"

From cppreference.com
< cpp‎ | algorithm
 
m (Parameters: use link to synopsis.)
 
(80 intermediate revisions by 27 users not shown)
Line 1: Line 1:
 
{{cpp/title|transform}}
 
{{cpp/title|transform}}
{{cpp/algorithm/sidebar}}
+
{{cpp/algorithm/}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list header | algorithm}}
+
{{header|algorithm}}
{{ddcl list item | num=1 |
+
{{|num=1|
template< class InputIterator, class OutputIterator, class UnaryOperation >
+
template< class , class , class >
OutputIterator transform( InputIterator first1, InputIterator1 last1,
+
transform( first1, last1,
                          OutputIterator d_first, UnaryOperation unary_op );
+
d_first, unary_op );
 
}}
 
}}
{{ddcl list item | num=2 |
+
{{|num=2|
template< class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation >
+
template< class ,
OutputIterator transform( InputIterator1 first1, InputIterator1 last1,
+
class , class , class >
                          InputIterator2 first2, OutputIterator d_first, BinaryOperation binary_op );
+
transform(
 +
first1, last1,
 +
d_first, );
 
}}
 
}}
{{ddcl list end}}
+
{{
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
end}}
  
Applies the given function to a range and stores the result in another range, beginning at {{tt|d_first}}. In the first version unary operation {{tt|unary_op}} is applied to the range, defined by {{tt|[first1, last1)}}. In the second version binary operation {{tt|binary_op}} is applied to pairs of elements from two ranges: one defined by {{tt|[first1, last1)}} and other beginning at {{tt|first2}}.
+
{{tt|}} the to the range, the from {{|}}.
  
<!-- ======== -->
+
{{}} {{|first1last1}}
{{params}}
+
{{|}} of the
{{param list begin}}
+
{{||}}
{{param list item | first1, last1 | the first range of elements to transform}}
+
{{|}} {{}}
{{param list item | first2 | the beginning of the second range of elements to transform}}
+
{{param list item | d_first | the beginning of the destination range}}
+
{{param list op1 | unary_op | rp=OutputIterator | p1=InputIterator}}
+
{{param list op2 | binary_op | rp=OutputIterator | p1=InputIterator1 | p2=InputIterator2}}
+
{{param list end}}
+
  
<!-- ======== -->
+
{{returns}}
+
 +
 +
 +
{{}}
  
output iterator to the element past the last element transformed.
+
to .
 +
  
<!-- ======== -->
+
======
{{eq fun}}
+
{{eq fun cpp
+
=
| 1=
+
template<class InputIterator, class OutputIterator, class UnaryOperation>
+
OutputIterator copy(InputIterator first1, InputIterator last1,
+
                    OutputIterator d_first, UnaryOperation unary_op)
+
=
 +
 +
 +
 +
 +
 +
 +
 
 +
 +
 +
 
 +
 +
-
 +
-
 +
{{}}
 +
 
 +
 +
{{cpp
 +
 
 +
 +
 +
|1=
 +
template<class , class , class >
 +
 +
(first1, last1,
 +
d_first, unary_op)
 
{
 
{
     while (first1 != last1) {
+
     (first1 != last1)
         *d_first++ = unary_op(*first1++);
+
         *d_first = unary_op(*first1);
    }
+
 
 
     return d_first;
 
     return d_first;
 
}
 
}
| 2=
+
|2=
template<class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
+
template<class , class ,  
OutputIterator copy(InputIterator first1, InputIterator last1,
+
class , class >
                    InputIterator first2, OutputIterator d_first, BinaryOperation binary_op)
+
 +
(first1, last1, first2,
 +
d_first, binary_op)
 
{
 
{
     while (first1 != last1) {
+
     (first1 != last1)
         *d_first++ = binary_op(*first1++, *first2++);
+
         *d_first = binary_op(*first1, *first2);
    }
+
 
 
     return d_first;
 
     return d_first;
 
}
 
}
 
}}
 
}}
  
<!-- ======== -->
+
======
{{example}}
+
{{}}