◐ Shell
clean mode source ↗

std::valarray::apply — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

valarray<T> apply( T func(T) ) const;

valarray<T> apply( T func(const T&) ) const;

Retourne une nouvelle valarray de la même taille avec des valeurs qui sont acquises par l'application func fonction des valeurs précédentes des éléments .

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.

Paramètres

func -

fonctionner à appliquer aux valeurs

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.

Retourne la valeur

Le valarray résultant des valeurs acquises par l'application func fonction .

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.

Notes

La fonction peut être mise en œuvre avec le type de retour différent de std::valarray. Dans ce cas, le type de remplacement a les propriétés suivantes:

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.

  • Toutes les fonctions de membre de const std::valarray sont fournis .

    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 et std::indirect_array peut être construit à partir du type de remplacement .

    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.

  • Toutes les fonctions acceptant un argument de type de const std::valarray& devrait également accepter le type de remplacement .

    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.

  • Toutes les fonctions qui acceptent deux arguments de type de const std::valarray& devrait accepter toutes les combinaisons de const std::valarray& et le type de remplacement .

    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.

Exemple

calcule et imprime les 10 premières factorielles

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';
}

Résultat :

1 2 6 24 120 720 5040 40320 362880 3628800

Voir aussi

applique une fonction à une série d'éléments

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.


(fonction générique) [edit]