C++ Standard Library C++ STL Library

C++ - <valarray>



C++ <valarray>

A valarray object is designed to hold an array of values. It supports element-wise mathematical operations and various forms of generalized subscript operators, slicing and indirect access. Most of the mathematical operations can be directly applied to valarray objects, including arithmetical and comparison operators, affecting all its elements.

Syntax

template <class T> class valarray;

Parameters

T Type of the elements stored in the valarray.

Member Types

Member typesDefinition
value_type T (First template parameter)

C++ <valarray> - Member Functions

The C++ valarray has a number of member functions which are listed below:

FunctionsDescription
apply() Applies a function to every element of a valarray.
max() Returns maximum value of elements of valarray.
min() Returns minimum value of elements of valarray.
resize() Changes the size of valarray.
size() Returns the size of the valarray.
shift() Zero-filling shift the elements of the valarray.
cshift() Circular shift the elements of the valarray.
sum() Returns sum of all elements of valarray.
swap() Exchanges elements between two valarrays.

Operators

FunctionsDescription
operator+ Applies unary plus operator to each element of the valarray.
operator- Applies unary minus operator to each element of the valarray.
operator~ Applies unary bitwise not operator to each element of the valarray.
operator! Applies unary not operator to each element of the valarray.
operator+= Applies plus AND assignment operator to each element of the valarray.
operator-= Applies minus AND assignment operator to each element of the valarray.
operator*= Applies multiply AND assignment operator to each element of the valarray.
operator/= Applies divide AND assignment operator to each element of the valarray.
operator%= Applies modulo AND assignment operator to each element of the valarray.
operator&= Applies bitwise AND assignment operator to each element of the valarray.
operator|= Applies bitwise OR and assignment operator to each element of the valarray.
operator^= Applies bitwise XOR and assignment operator to each element of the valarray.
operator>>= Applies right shift AND assignment operator to each element of the valarray.
operator<<= Applies left shift AND assignment operator to each element of the valarray.

C++ <valarray> - Non-member Functions

Trigonometric Functions

FunctionsDescription
sin() Applies sin() function to each element of valarray.
cos() Applies cos() function to each element of valarray.
tan() Applies tan() function to each element of valarray.
asin() Applies asin() function to each element of valarray.
acos() Applies acos() function to each element of valarray.
atan() Applies atan() function to each element of valarray.
atan2() Applies atan2() function to a valarray and a value.

Hyperbolic Functions

FunctionsDescription
sinh() Applies sinh() function to each element of valarray.
cosh() Applies cosh() function to each element of valarray.
tanh() Applies tanh() function to each element of valarray.

Other Functions

FunctionsDescription
abs() Compute absolute value of each element of valarray.
exp() Applies exp() function to each element of valarray.
log() Applies log() function to each element of valarray.
log10() Applies log10() function to each element of valarray.
pow() Applies pow() function to two valarrays or a valarray and a value.
sqrt() Applies sqrt() function to each element of valarray.
swap() Exchanges elements between two valarrays.
begin() Returns iterator pointing to the first element of the valarray.
end() Returns iterator pointing to the past-the-last element of the valarray.

Operators

FunctionsDescription
operator+ Applies binary plus operator to each element of two valarrays, or a valarray and a value.
operator- Applies binary minus operator to each element of two valarrays, or a valarray and a value.
operator* Applies binary multiply operator to each element of two valarrays, or a valarray and a value.
operator/ Applies binary divide operator to each element of two valarrays, or a valarray and a value.
operator% Applies binary modulo operator to each element of two valarrays, or a valarray and a value.
operator& Applies binary bitwise AND operator to each element of two valarrays, or a valarray and a value.
operator| Applies binary bitwise OR operator to each element of two valarrays, or a valarray and a value.
operator^ Applies binary bitwise XOR operator to each element of two valarrays, or a valarray and a value.
operator>> Applies binary right shift operator to each element of two valarrays, or a valarray and a value.
operator<< Applies binary left shift operator to each element of two valarrays, or a valarray and a value.
operator&& Applies binary AND operator to each element of two valarrays, or a valarray and a value.
operator|| Applies binary OR operator to each element of two valarrays, or a valarray and a value.
operator== Checks whether two valarrays, or a valarray and a value are equal or not, element-wise.
operator!= Checks whether two valarrays, or a valarray and a value are unequal or not, element-wise.
operator< Checks whether valarray is less than the other valarray or a value, element-wise.
operator> Checks whether valarray is greater than the other valarray or a value, element-wise.
operator<= Checks whether valarray is less than or equal to the other valarray or a value, element-wise.
operator>= Checks whether valarray is greater than or equal to the other valarray or a value, element-wise.

C++ <valarray> - Helper classes