std::valarray
| Defined in header <valarray> | ||
|---|---|---|
| template< class T > class valarray; | 
std::valarray is the class for representing and manipulating arrays of values. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access.
Notes
std::valarray and helper classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized similar to the effect of the keyword restrict in the C programming language. In addition, functions and operators that take valarray arguments are allowed to return proxy objects to make it possible for the compiler to optimize an expression such as v1 = a*v2 + v3; as a single loop that executes v1[i] = a*v2[i] + v3[i]; avoiding any temporaries or multiple passes. However, expression templates make the same optimization technique available for any C++ container, and the majority of numeric libraries prefer expression templates to valarrays for flexibility. Some C++ standard library implementations use expression templates to implement efficient operations on std::valarray (e.g. GNU libstdc++ and LLVM libc++). Only rarely are valarrays optimized any further, as in e.g. Intel Integrated Performance Primitives.
Template parameters
| T | - | the type of the elements. The type must meet the NumericType requirements | 
Member types
| Member type | Definition | 
|---|---|
| value_type | T | 
Member functions
| constructs new numeric array (public member function) | |
| destructs the numeric array (public member function) | |
| assigns the contents (public member function) | |
| get/set valarray element, slice, or mask (public member function) | |
| applies a unary arithmetic operator to each element of the valarray (public member function) | |
| applies compound assignment operator to each element of the valarray (public member function) | |
| swaps with another valarray (public member function) | |
| returns the size of valarray (public member function) | |
| changes the size of valarray (public member function) | |
| calculates the sum of all elements (public member function) | |
| returns the smallest element (public member function) | |
| returns the largest element (public member function) | |
| zero-filling shift the elements of the valarray (public member function) | |
| circular shift of the elements of the valarray (public member function) | |
| applies a function to every element of a valarray (public member function) | 
Non-member functions
| (C++11) | specializes the std::swap()algorithm(function template) | 
| (C++11) | specializes std::begin(function template) | 
| (C++11) | specializes std::end(function template) | 
| applies binary operators to each element of two valarrays, or a valarray and a value (function template) | |
| compares two valarrays or a valarray with a value (function template) | |
| applies the function std::absto each element of valarray(function template) | |
| Exponential functions | |
| applies the function std::expto each element of valarray(function template) | |
| applies the function std::logto each element of valarray(function template) | |
| applies the function std::log10to each element of valarray(function template) | |
| Power functions | |
| applies the function std::powto two valarrays or a valarray and a value(function template) | |
| applies the function std::sqrtto each element of valarray(function template) | |
| Trigonometric functions | |
| applies the function std::sinto each element of valarray(function template) | |
| applies the function std::costo each element of valarray(function template) | |
| applies the function std::tanto each element of valarray(function template) | |
| applies the function std::asinto each element of valarray(function template) | |
| applies the function std::acosto each element of valarray(function template) | |
| applies the function std::atanto each element of valarray(function template) | |
| applies the function std::atan2to a valarray and a value(function template) | |
| Hyperbolic functions | |
| applies the function std::sinhto each element of valarray(function template) | |
| applies the function std::coshto each element of valarray(function template) | |
| applies the function std::tanhto each element of valarray(function template) | |
Helper classes
| BLAS-like slice of a valarray: starting index, length, stride (class) | |
| proxy to a subset of a valarray after applying a slice (class template) | |
| generalized slice of a valarray: starting index, set of lengths, set of strides (class) | |
| proxy to a subset of a valarray after applying a gslice (class template) | |
| proxy to a subset of a valarray after applying a boolean mask operator[](class template) | |
| proxy to a subset of a valarray after applying indirect operator[](class template) | 
Deduction guides(since C++17)
    © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
    http://en.cppreference.com/w/cpp/numeric/valarray