[valarray.assign]

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

## 29.6 Numeric arrays [[numarray]](numarray#valarray.assign)

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

#### 29.6.2.3 Assignment [valarray.assign]

[ð](#lib:operator=,valarray)

`valarray& operator=(const valarray& v);
`

[1](#1)

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

*Effects*: Each element of the*this array is assigned the value of the corresponding element of v[.](#1.sentence-1)

If the length of v is not equal to the length of *this,
resizes *this to make the two arrays the same length,
as if by calling resize(v.size()), before performing the assignment[.](#1.sentence-2)

[2](#2)

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

*Postconditions*: size() == v.size()[.](#2.sentence-1)

[3](#3)

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

*Returns*: *this[.](#3.sentence-1)

[ð](#lib:operator=,valarray_)

`valarray& operator=(valarray&& v) noexcept;
`

[4](#4)

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

*Effects*: *this obtains the value of v[.](#4.sentence-1)

The value of v after the assignment is not specified[.](#4.sentence-2)

[5](#5)

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

*Returns*: *this[.](#5.sentence-1)

[6](#6)

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

*Complexity*: Linear[.](#6.sentence-1)

[ð](#lib:operator=,valarray__)

`valarray& operator=(initializer_list<T> il);
`

[7](#7)

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

*Effects*: Equivalent to: return *this = valarray(il);

[ð](#lib:operator=,valarray___)

`valarray& operator=(const T& v);
`

[8](#8)

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

*Effects*: Assigns v to each element of *this[.](#8.sentence-1)

[9](#9)

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

*Returns*: *this[.](#9.sentence-1)

[ð](#lib:operator=,valarray____)

`valarray& operator=(const slice_array<T>&);
valarray& operator=(const gslice_array<T>&);
valarray& operator=(const mask_array<T>&);
valarray& operator=(const indirect_array<T>&);
`

[10](#10)

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

*Preconditions*: The length of the array to which the argument refers equals size()[.](#10.sentence-1)

The value of an element in the left-hand side of a valarray assignment
operator does not depend on the value of another element in that left-hand side[.](#10.sentence-2)

[11](#11)

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

These operators allow the results of a generalized subscripting operation
to be assigned directly to avalarray[.](#11.sentence-1)
