std::transform
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <algorithm>
|
||
template< class InputIt, class OutputIt, class UnaryOperation > OutputIt transform( InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op ); |
(1) | |
template< class InputIt1, class InputIt2, class OutputIt, class BinaryOperation > OutputIt transform( InputIt1 first1, InputIt1 last1, InputIt2 first2, OutputIt d_first, BinaryOperation binary_op ); |
(2) | |
std::transform aplica a função dada a uma ampla e armazena o resultado em outro intervalo, com início às d_first. std::transform applies the given function to a range and stores the result in another range, beginning at d_first. You can help to correct and verify the translation. Click here for instructions.
unary_op operação unária é aplicado ao intervalo definido por [first1, last1). Na segunda versão da binary_op operação de binário é aplicado a pares de elementos de duas cadeias: uma definida por [first1, last1) eo início de outro first2.unary_op is applied to the range defined by [first1, last1). In the second version the binary operation binary_op is applied to pairs of elements from two ranges: one defined by [first1, last1) and the other beginning at first2.You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| first1, last1 | - | a primeira gama de elementos para transformar
Original: the first range of elements to transform The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first2 | - | o início da segunda gama de elementos de transformar
Original: the beginning of the second range of elements to transform The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| d_first | - | o início do intervalo de destino, pode ser igual ou
first1 first2 Original: the beginning of the destination range, may be equal to first1 or first2 The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| unary_op | - | unary operation function object that will be applied. The signature of the function should be equivalent to the following:
The signature does not need to have |
| binary_op | - | binary operation function object that will be applied. The signature of the function should be equivalent to the following:
The signature does not need to have |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
-InputIt1 must meet the requirements of InputIterator.
| ||
-InputIt2 must meet the requirements of InputIterator.
| ||
-OutputIt must meet the requirements of OutputIterator.
| ||
Valor de retorno
You can help to correct and verify the translation. Click here for instructions.
Complexidade
1)
std::distance(first1, last1) aplicações de unary_opstd::distance(first1, last1) applications of unary_opYou can help to correct and verify the translation. Click here for instructions.
2)
std::distance(first1, last1) aplicações de binary_opstd::distance(first1, last1) applications of binary_opYou can help to correct and verify the translation. Click here for instructions.
Requisitos
unary_op e binary_op não têm efeitos colaterais. (até C++11)unary_op and binary_op have no side effects. (até C++11)You can help to correct and verify the translation. Click here for instructions.
unary_op e binary_op não invalidam qualquer iteradores, incluindo os iteradores finais, ou modificar quaisquer elementos das cadeias envolvidas. (desde C++11)unary_op and binary_op do not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (desde C++11)You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Possível implementação
| First version |
|---|
template<class InputIt, class OutputIt, class UnaryOperation>
OutputIt transform(InputIt first1, InputIt last1, OutputIt d_first,
UnaryOperation unary_op)
{
while (first1 != last1) {
*d_first++ = unary_op(*first1++);
}
return d_first;
}
|
| Second version |
template<class InputIt1, class InputIt2,
class OutputIt, class BinaryOperation>
OutputIt transform(InputIt first1, InputIt last1, InputIt first2,
OutputIt d_first, BinaryOperation binary_op)
{
while (first1 != last1) {
*d_first++ = binary_op(*first1++, *first2++);
}
return d_first;
}
|
Exemplo
You can help to correct and verify the translation. Click here for instructions.
#include <string>
#include <cctype>
#include <algorithm>
#include <iostream>
int main()
{
std::string s("hello");
std::transform(s.begin(), s.end(), s.begin(), (int (*)(int))std::toupper);
std::cout << s;
}
Saída:
HELLO
