Standard C++ Library Reference ISO/IEC (VERSION3)
Ty sum() const;
Ty max() const;
Ty min() const;
valarray<Ty> shift(int count) const;
valarray<Ty> cshift(int count) const;
valarray<Ty> apply(Ty func(Ty)) const;
valarray<Ty> apply(Ty func(const Ty&)) const;
void resize(size_t newsize);
void resize(size_t newsize, const Ty& val);
};
The template class describes an object that controls a varying-length sequence of elements of type Ty. The
sequence is stored as an array of Ty. It differs from template class vector in two important ways:
It defines numerous arithmetic operations between corresponding elements of valarray<Ty>
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<Ty> object, by overloading
operator[].
●
An object of class Ty:
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. And none of the operations on objects of class Ty may throw exceptions.
valarray::apply
valarray<Ty> apply(Ty func(Ty)) const;
valarray<Ty> apply(Ty func(const Ty&)) const;
The member function returns an object of class valarray<Ty>, of length size(), each of whose
elements I is func((*this)[I]).
valarray::cshift
valarray<Ty> cshift(int count) const;
The member function returns an object of class valarray<Ty>, of length size(), each of whose
elements I is (*this)[(I + count) % size()]. Thus, if element zero is taken as the leftmost
element, a positive value of count shifts the elements circularly left count places.
valarray::max
Ty max() const;
The member function returns the value of the largest element of *this, which must have nonzero length. If
the length is greater than one, it compares values by applying operator< between pairs of corresponding
elements of class Ty.