std::transform - cppreference.com
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>
| Elemento definito nell'header <algorithm> |
||
|
|
(1) | |
|
|
(2) | |
std::transform applica la funzione specificata a una vasta e memorizza il risultato in un altro campo, con inizio alle d_first.
Original:
std::transform applies the given function to a range and stores the result in another range, beginning at d_first.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Nella prima versione unary_op operazione unaria viene applicato alla serie definita da [first1, last1). Nella seconda versione del binary_op operazione binaria viene applicata a coppie di elementi da due intervalli: uno definito dal [first1, last1) e l'altro a inizio first2.
Original:
In the first version unary operation 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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Parametri
| first1, last1 | - | la prima gamma di elementi per trasformare Original: the first range of elements to transform The text has been machine-translated via Google Translate. |
| first2 | - | all'inizio del secondo intervallo di elementi da trasformare Original: the beginning of the second range of elements to transform The text has been machine-translated via Google Translate. |
| d_first | - | l'inizio del campo di destinazione, può essere uguale o Original: the beginning of the destination range, may be equal to The text has been machine-translated via Google Translate. |
| 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.
| ||
Valore di ritorno
iteratore uscita all'elemento passato l'ultimo elemento trasformato.
Original:
output iterator to the element past the last element transformed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Complessità
1)
esattamente std::distance(first1, last1) applicazioni di unary_op
Original:
exactly std::distance(first1, last1) applications of unary_op
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
esattamente std::distance(first1, last1) applicazioni di binary_op
Original:
exactly std::distance(first1, last1) applications of binary_op
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Requisiti
unary_op binary_op e non hanno effetti collaterali. (fino al c++11)
Original:
unary_op and binary_op have no side effects. (fino al c++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unary_op e binary_op non invalidare le iteratori, inclusi gli iteratori finali, o modificare tutti gli elementi delle catene coinvolte. (dal C++11)
Original:
unary_op and binary_op do not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (dal C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
L'intento di questi requisiti è quello di consentire implementazioni parallele o out-of-order di std::transform. Per applicare una funzione a una sequenza in ordine, utilizzare std::for_each.
Original:
The intent of these requirements is to allow parallel or out-of-order implementations of std::transform. To apply a function to a sequence in-order, use std::for_each.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Possibile implementazione
| 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; } |
Esempio
Il codice seguente utilizza trasformazione per convertire una stringa in lettere maiuscole utilizzando la funzione toupper:
Original:
The following code uses transform to convert a string to uppercase using the toupper function:
The text has been machine-translated via Google Translate.
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; }
Output:
Vedi anche
applica una funzione ad una serie di elementi Original: applies a function to a range of elements The text has been machine-translated via Google Translate. (funzione di modello) [modifica] | |