std::valarray::apply
来自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. |
| valarray<T> apply( T func(T) ) const; |
||
| valarray<T> apply( T func(const T&) ) const; |
||
通过施加到先前的值的元素的功能
func购入的大小相同的值返回一个新的valarray.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.
目录 |
[编辑] 参数
| func | - | 功能适用的值
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. |
[编辑] 返回值
由此产生的valarray与应用功能
func,获取的值.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.
[编辑] 注释
该功能可以实现从std::valarray不同的返回类型。在这种情况下,替换类型具有以下属性:
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.
- const提供的所有std::valarray成员函数.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可以由更换型.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. - 所有的函数接受一个参数的类型const std::valarray&也应接受替换类型.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. - 接受两个参数的类型const std::valarray&应该接受所有的功能const std::valarray&的每个组合和置换型.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.
-
[编辑] 为例
第10阶乘计算和打印
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
[编辑] 另请参阅
| 某一范围的元素应用一个函数 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. (函数模板) | |