cpp/numeric/valarray/apply: differenze tra le versioni

Da cppreference.com.
< cpp‎ | numeric‎ | valarray
m (r2.7.3) (Bot: Aggiungo de, en, es, fr, ja, pt, ru, zh)
m (Use {{lc}}. Update links. Various fixes.)
 
Riga 2:Riga 2:
 
{{cpp/numeric/valarray/title|apply}}
 
{{cpp/numeric/valarray/title|apply}}
 
{{cpp/numeric/valarray/navbar}}
 
{{cpp/numeric/valarray/navbar}}
{{ddcl list begin}}
+
{{dcl begin}}
{{ddcl list item |  
+
{{dcl |  
 
valarray<T> apply( T func(T) ) const;
 
valarray<T> apply( T func(T) ) const;
 
}}
 
}}
{{ddcl list item |
+
{{dcl |
 
valarray<T> apply( T func(const T&) ) const;
 
valarray<T> apply( T func(const T&) ) const;
 
}}
 
}}
{{ddcl list end}}
+
{{dcl end}}
  
 
{{tr|Restituisce una nuova valarray della stessa dimensione, con valori che vengono acquisiti applicando {{tt|func}} funzione ai valori precedenti degli elementi.|Returns a new valarray of the same size with values which are acquired by applying function {{tt|func}} to the previous values of the elements.}}
 
{{tr|Restituisce una nuova valarray della stessa dimensione, con valori che vengono acquisiti applicando {{tt|func}} funzione ai valori precedenti degli elementi.|Returns a new valarray of the same size with values which are acquired by applying function {{tt|func}} to the previous values of the elements.}}
  
 
===Parametri===
 
===Parametri===
{{param list begin}}
+
{{par begin}}
{{param list item | func |{{tr| funzione da applicare ai valori| function to apply to the values}}}}
+
{{par | func |{{tr| funzione da applicare ai valori| function to apply to the values}}}}
{{param list end}}
+
{{par end}}
  
 
===Valore di ritorno===
 
===Valore di ritorno===
Riga 48:Riga 48:
  
 
===Vedi anche===
 
===Vedi anche===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/algorithm/dcl list for_each}}
+
{{dsc inc | cpp/algorithm/dsc for_each}}
{{dcl list end}}
+
{{dsc end}}
  
 
[[de:cpp/numeric/valarray/apply]]
 
[[de:cpp/numeric/valarray/apply]]

Versione attuale delle 14:53, 2 lug 2013

 
 
Numeri libreria
Comuni funzioni matematiche
Virgola mobile ambiente
I numeri complessi
Array numerici
Pseudo-casuale generazione
In fase di compilazione aritmetica razionale (C++11)
Generici operazioni numeriche
Original:
Generic numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iota(C++11)
accumulate
inner_product
adjacent_difference
partial_sum
 
 
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.

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.

[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.
  • Tutte le funzioni di membro const std::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_array std::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 const std::valarray& tipo devono anche accettare il tipo di sostituzione.
    Original:
    All functions accepting a arguments of type const std::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 const std::valarray& dovrebbe accettare ogni combinazione di const std::valarray& e il tipo di sostituzione.
    Original:
    All functions accepting two arguments of type const std::valarray& should accept every combination of const std::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.

#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 {
                    return std::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) [modifica]