[template.valarray.overview]

# 29 Numerics library [[numerics]](./#numerics)

## 29.6 Numeric arrays [[numarray]](numarray#template.valarray.overview)

### 29.6.2 Class template valarray [[template.valarray]](template.valarray#overview)

#### 29.6.2.1 Overview [template.valarray.overview]

[ð](#lib:valarray)

namespace std {template<class T> class valarray {public:using value_type = T; // [[valarray.cons]](valarray.cons "29.6.2.2 Constructors"), construct/destroy valarray(); explicit valarray(size_t);
 valarray(const T&, size_t);
 valarray(const T*, size_t);
 valarray(const valarray&);
 valarray(valarray&&) noexcept;
 valarray(const slice_array<T>&);
 valarray(const gslice_array<T>&);
 valarray(const mask_array<T>&);
 valarray(const indirect_array<T>&);
 valarray(initializer_list<T>); ~valarray(); // [[valarray.assign]](valarray.assign "29.6.2.3 Assignment"), assignment valarray& operator=(const valarray&);
 valarray& operator=(valarray&&) noexcept;
 valarray& operator=(initializer_list<T>);
 valarray& operator=(const T&);
 valarray& operator=(const slice_array<T>&);
 valarray& operator=(const gslice_array<T>&);
 valarray& operator=(const mask_array<T>&);
 valarray& operator=(const indirect_array<T>&); // [[valarray.access]](valarray.access "29.6.2.4 Element access"), element accessconst T& operator[](size_t) const;
 T& operator[](size_t); // [[valarray.sub]](valarray.sub "29.6.2.5 Subset operations"), subset operations valarray operator[](slice) const;
 slice_array<T> operator[](slice);
 valarray operator[](const gslice&) const;
 gslice_array<T> operator[](const gslice&);
 valarray operator[](const valarray<bool>&) const;
 mask_array<T> operator[](const valarray<bool>&);
 valarray operator[](const valarray<size_t>&) const;
 indirect_array<T> operator[](const valarray<size_t>&); // [[valarray.unary]](valarray.unary "29.6.2.6 Unary operators"), unary operators valarray operator+() const;
 valarray operator-() const;
 valarray operator~() const;
 valarray<bool> operator!() const; // [[valarray.cassign]](valarray.cassign "29.6.2.7 Compound assignment"), compound assignment valarray& operator*= (const T&);
 valarray& operator/= (const T&);
 valarray& operator%= (const T&);
 valarray& operator+= (const T&);
 valarray& operator-= (const T&);
 valarray& operator^= (const T&);
 valarray& operator&= (const T&);
 valarray& operator|= (const T&);
 valarray& operator<<=(const T&);
 valarray& operator>>=(const T&);

 valarray& operator*= (const valarray&);
 valarray& operator/= (const valarray&);
 valarray& operator%= (const valarray&);
 valarray& operator+= (const valarray&);
 valarray& operator-= (const valarray&);
 valarray& operator^= (const valarray&);
 valarray& operator|= (const valarray&);
 valarray& operator&= (const valarray&);
 valarray& operator<<=(const valarray&);
 valarray& operator>>=(const valarray&); // [[valarray.members]](valarray.members "29.6.2.8 Member functions"), member functionsvoid swap(valarray&) noexcept;

 size_t size() const;

 T sum() const;
 T min() const;
 T max() const;

 valarray shift (int) const;
 valarray cshift(int) const;
 valarray apply(T func(T)) const;
 valarray apply(T func(const T&)) const; void resize(size_t sz, T c = T()); }; template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7299)

The
class templatevalarray<T> is a
one-dimensional smart array, with elements numbered sequentially from zero[.](#1.sentence-1)

It is a representation of the mathematical concept
of an ordered set of values[.](#1.sentence-2)

For convenience, an object of type valarray<T> is referred
to as an âarrayâ throughout the remainder of [[numarray]](numarray "29.6 Numeric arrays")[.](#1.sentence-3)

The illusion of higher dimensionality
may be produced by the familiar idiom of computed indices, together
with the powerful subsetting capabilities provided
by the generalized subscript operators[.](#1.sentence-4)[248](#footnote-248 "The intent is to specify an array template that has the minimum functionality necessary to address aliasing ambiguities and the proliferation of temporary objects. Thus, the valarray template is neither a matrix class nor a field class. However, it is a very useful building block for designing such classes.")

[248)](#footnote-248)[248)](#footnoteref-248)

The intent is to specify
an array template that has the minimum functionality
necessary to address aliasing ambiguities and the proliferation of
temporary objects[.](#footnote-248.sentence-1)

Thus, thevalarray template is neither a
matrix class nor a field class[.](#footnote-248.sentence-2)

However, it is a very useful building block for designing such classes[.](#footnote-248.sentence-3)
