std::valarray::apply
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. |
valarray<T> apply( T func(T))const; | ||
valarray<T> apply( T func(const T&))const; | ||
Restituisce una nuova valarray della stessa dimensione, con valori che vengono acquisiti applicando
func
funzione ai valori precedenti degli elementi.Original:
Returns a new valarray of the same size with values which are acquired by applying function
func
to the previous values of the elements.The text has been machine-translated via Google Translate.
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.
Indice |
[modifica]Parametri
func | - | funzione da applicare ai valori Original: function to apply to the values The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica]Valore di ritorno
Il valarray risultante con i valori acquisiti applicando
func
funzione.Original:
The resulting valarray with values acquired by applying function
func
.The text has been machine-translated via Google Translate.
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.
[modifica]Note
La funzione può essere implementata con il tipo restituito diverso da std::valarray. In questo caso, il tipo di sostituzione ha le seguenti proprietà:
Original:
The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:
The text has been machine-translated via Google Translate.
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.
- Tutte le funzioni di membro conststd::valarray sono forniti.Original:All const member functions of std::valarray are provided.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - std::valarray, std::slice_array, std::gslice_array, std::mask_arraystd::indirect_array e può essere costruito con il tipo di sostituzione.Original:std::valarray, std::slice_array, std::gslice_array, std::mask_array and std::indirect_array can be constructed from the replacement type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Tutte le funzioni che accettano un argomento di conststd::valarray& tipo devono anche accettare il tipo di sostituzione.Original:All functions accepting a arguments of type conststd::valarray& should also accept the replacement type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Tutte le funzioni che accettano due argomenti di tipo conststd::valarray& dovrebbe accettare ogni combinazione di conststd::valarray& e il tipo di sostituzione.Original:All functions accepting two arguments of type conststd::valarray& should accept every combination of conststd::valarray& and the replacement type.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[modifica]Esempio
calcola e stampa i primi 10 fattoriali
Original:
calculates and prints the first 10 factorials
The text has been machine-translated via Google Translate.
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.
#include <iostream>#include <valarray>#include <cmath> int main(){std::valarray<int> v ={1,2,3,4,5,6,7,8,9,10}; v = v.apply([](int n)->int{returnstd::round(std::tgamma(n+1));});for(auto n : v){std::cout<< n <<' ';}std::cout<<'\n';}
Output:
1 2 6 24 120 720 5040 40320 362880 3628800
[modifica]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. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) |