valarray Class

The template class describes an object that controls a sequence of elements of type Type that are stored as an array, designed for performing high-speed mathematical operations, and optimized for computational performance.

Remarks

The class is a representation of the mathematical concept of an ordered set of values and the elements are numbered sequentially from zero. The class is described as a near container because it supports some, but not all, of the capabilities that first-class sequence containers, such as vector, support. It differs from template class vector in two important ways:

  • It defines numerous arithmetic operations between corresponding elements of valarray<Type> objects of the same type and length, such as xarr = cos(yarr) + sin(zarr).

  • It defines a variety of interesting ways to subscript a valarray<Type> object, by overloading operator[].

An object of class Type:

  • Has a public default constructor, destructor, copy constructor, and assignment operator, with conventional behavior.

  • Defines the arithmetic operators and math functions, as needed, that are defined for the floating-point types, with conventional behavior.

In particular, no subtle differences may exist between copy construction and default construction followed by assignment. None of the operations on objects of class Type may throw exceptions.

Constructors

valarray

Constructs a valarray of a specific size or with elements of a specific value or as a copy of another valarray or subset of another valarray.

Typedefs

value_type

A type that represents the type of element stored in a valarray.

Member Functions

apply

Applies a specified function to each element of a valarray.

cshift

Cyclically shifts all the elements in a valarray by a specified number of positions.

free

Frees the memory used by the valarray.

max

Finds the largest element in a valarray.

min

Finds the smallest element in a valarray.

resize

Changes the number of elements in a valarray to a specified number, adding or removing elements as required.

shift

Shifts all the elements in a valarray by a specified number of positions.

size

Finds the number of elements in a valarray.

sum

Determines the sum of all the elements in a valarray of nonzero length.

swap

Operators

operator!

A unary operator that obtains the logical NOT values of each element in a valarray.

operator%=

Obtains the remainder of dividing the elements of an array element-wise either by a specified valarray or by a value of the element type.

operator&=

Obtains the bitwise AND of elements in an array either with the corresponding elements in a specified valarray or with a value of the element type.

operator>>=

Right-shifts the bits for each element of a valarray operand a specified number of positions or by an element-wise amount specified by a second valarray.

operator<<=

Left-shifts the bits for each element of a valarray operand a specified number of positions or by an element-wise amount specified by a second valarray.

operator*=

Multiplies the elements of a specified valarray or a value of the element type, element-wise, to an operand valarray.

operator+

A unary operator that applies a plus to each element in a valarray.

operator+=

Adds the elements of a specified valarray or a value of the element type, element-wise, to an operand valarray.

operator-

A unary operator that applies a minus to each element in a valarray.

operator-=

Subtracts the elements of a specified valarray or a value of the element type, element-wise, from an operand valarray.

operator/=

Divides an operand valarray element-wise by the elements of a specified valarray or a value of the element type.

operator=

Assigns elements to a valarray whose values are specified either directly or as part of some other valarray or by a slice_array, gslice_array, mask_array, or indirect_array.

operator[]

Returns a reference to an element or its value at specified index or a specified subset.

operator^=

Obtains the element-wise exclusive logical or operator (XOR) of an array with either a specified valarray or a value of the element type.

operator|=

Obtains the bitwise OR of elements in an array either with the corresponding elements in a specified valarray or with a value of the element type.

operator~

A unary operator that obtains the bitwise NOT values of each element in a valarray.

Requirements

Header: <valarray>

Namespace: std

See Also

Reference

Thread Safety in the C++ Standard Library