Espacios de nombres
Variantes
Acciones

std::valarray::apply

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

 
 
Numéricos biblioteca
Funciones matemáticas comunes
Floating-point medio ambiente
Los números complejos
Matrices numéricas
Pseudo-aleatoria de generación de números
En tiempo de compilación aritmética racional (C++11)
Genéricos operaciones 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.
iota(C++11)
accumulate
inner_product
adjacent_difference
partial_sum
 
std::valarray
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clases de ayuda
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
valarray<T> apply( T func(T) ) const;
valarray<T> apply( T func(const T&) ) const;
Devuelve una valarray nuevo del mismo tamaño con valores que se adquieren mediante la aplicación de func función de los valores anteriores de los 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.

Contenido

[editar] Parámetros

func -
funcionar a aplicar a los 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

El valarray resultante con los valores adquiridos mediante la aplicación de func función .
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

La función se puede implementar con el tipo de retorno diferente de std::valarray. En este caso, el tipo de reemplazo tiene las siguientes propiedades:
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 las funciones miembro de const std::valarray se proporcionan .
    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 y puede ser construida a partir del tipo de reemplazo .
    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 las funciones que aceptan un argumento de tipo const std::valarray& también deben aceptar el tipo de reemplazo .
    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.
  • Todas las funciones que aceptan dos argumentos de tipo const std::valarray& debe aceptar todas las combinaciones de const std::valarray& y el tipo de reemplazo .
    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.

[editar] Ejemplo

calcula e imprime los 10 primeros factoriales
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

[editar] Ver también

se aplica una función a una serie 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.

(función de plantilla) [edit]