std::valarray::apply
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> valarray<T> apply( T func(T) ) const; |
||
valarray<T> apply( T func(const T&) ) const; |
||
Gibt ein neues valarray gleicher Größe mit den Werten, die durch Anwendung der Funktion
func zu den vorherigen Werten der Elemente erfasst werden .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.
Parameter
| func | - | Funktion, um die Werte zu übernehmen
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. |
Rückgabewert
Die daraus resultierende valarray mit Werten, indem Funktion
func erworben .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.
Notes
Die Funktion kann mit dem Rückgabetyp anders std::valarray umgesetzt werden. In diesem Fall weist die Ersetzungsart die folgenden Eigenschaften:
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.
- Alle
constElementfunktionen std::valarray bereitgestellt werden .Original:Allconstmember 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_arrayundstd::indirect_arraykann aus dem Ersatz-Typ gebaut werden .Original:std::valarray,std::slice_array,std::gslice_array,std::mask_arrayandstd::indirect_arraycan 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. - Alle Funktionen Annehmen eines Argumente des Typs
const std::valarray&sollten auch akzeptieren, den Austausch Typ .Original:All functions accepting a arguments of typeconst 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. - Alle Funktionen mit zwei Parametern vom Typ
const std::valarray&sollten akzeptieren, jede Kombination vonconst std::valarray&und den Ersatz Typ .Original:All functions accepting two arguments of typeconst std::valarray&should accept every combination ofconst 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.
Beispiel
berechnet und druckt die ersten 10 Fakultäten
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 {
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
Siehe auch
| Wendet eine Funktion auf eine Reihe von Elementen an (Funktions-Template) | |