Espaços nominais
Variantes
Acções

std::valarray::apply

Da cppreference.com
< cpp‎ | numeric‎ | valarray

 
 
Biblioteca numéricos
Funções matemáticas comuns
De ponto flutuante ambiente
Números complexos
Matrizes numéricas
Pseudo-aleatório de geração de números
Tempo de compilação aritmética racional(C++11)
Genéricos operações numéricas
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.
(C++11)
 
 
valarray<T> apply( T func(T))const;
valarray<T> apply( T func(const T&))const;
Devolve uma valarray novo do mesmo tamanho com valores que são obtidos através da aplicação de func função para os valores anteriores dos elementos.
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.

Índice

[editar]Parâmetros

func -
funcionar para aplicar os valores
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.

[editar]Valor de retorno

O valarray resultante com valores adquiridos através da aplicação func função.
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.

[editar]Notas

A função pode ser implementada com o tipo de retorno diferente de std::valarray. Neste caso, o tipo de substituição tem as seguintes propriedades:
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.
  • Todas as funções const membros std::valarray são fornecidos.
    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 pode ser construído a partir do tipo de reposição.
    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.
  • Todas as funções de aceitar um argumentos de conststd::valarray& tipo devem também aceitar o tipo de substituição.
    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.
  • Todas as funções que aceitam dois argumentos do tipo conststd::valarray& deve aceitar todas as combinações de conststd::valarray& e do tipo de substituição.
    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.

[editar]Exemplo

calcula e imprime os 10 primeiros fatoriais
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{returnstd::round(std::tgamma(n+1));});for(auto n : v){std::cout<< n <<' ';}std::cout<<'\n';}

Saída:

1 2 6 24 120 720 5040 40320 362880 3628800

[editar]Veja também

aplica-se uma função de uma série de elementos
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.

(modelo de função)[edit]
close