Пространства имён
Варианты
Действия

std::valarray::apply

Материал из cppreference.com

 
 
 
std::valarray
Член функций
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.
Не являющиеся членами функций
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.
Вспомогательные классы
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;
Возвращает новый valarray такого же размера, со значениями, которые приобретаются путем применения функции func к предыдущим значениям элементов.
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.

Содержание

[править] Параметры

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.

[править] Notes

Эта функция может быть реализована с возвращением тип отличается от 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.
  • Все 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.

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

Вывод:

1 2 6 24 120 720 5040 40320 362880 3628800

[править] См. также

применяет функцию к диапазону элементов
(шаблон функции) [edit]