public member function
<valarray>
std::valarray::apply
valarray apply (T func(T)) const;valarray apply (T func(const T&)) const;
Apply function
*this.
The valarray returned has the same length as *this.
Parameters
- func
- Pointer to a function taking an argument of type T (or a constant reference) and returning T.
T is the template argument of valarray (the value type).
Return value
A valarray object with the results of applying func to all the elements of*this.Example
|
|
Output:
Complexity
Depends on library implementation (operations may be parallelized).Iterator validity
No changes: Valid iterators, references and sub-arrays keep their validity.Data races
Both the valarray and its elements are accessed.Exception safety
If any operation performed on the elements throws an exception, it causes undefined behavior.If the function fails to allocate storage it may throw an exception (such as bad_alloc), although this is not mandated.
See also
- valarray::operator=
- Assign content (public member function)
- valarray operators
- Valarray operators (function)