public member function
<valarray>
std::valarray::operator=
| copy (1) | valarray& operator=(const valarray& x); |
|---|---|
| fill (2) | valarray& operator=(const T& val); |
| sub-array (3) | valarray& operator=(const slice_array<T>& sub);valarray& operator=(const gslice_array<T>& sub);valarray& operator=(const mask_array<T>& sub);valarray& operator=(const indirect_array<T>& sub); |
| copy/move (1) | valarray& operator=(const valarray& x);valarray& operator=(valarray&& x) noexcept; |
|---|---|
| fill (2) | valarray& operator=(const T& val); |
| sub-array (3) | valarray& operator=(const slice_array<T>& sub);valarray& operator=(const gslice_array<T>& sub);valarray& operator=(const mask_array<T>& sub);valarray& operator=(const indirect_array<T>& sub); |
Assign content
- (1) copy assignment
- Assigns the contents of x to
*this: each element is assigned the value of the corresponding element in x.
If the sizes do not match, the behavior is not defined.
- (2) fill assignment
- Assigns val to every element.
- (3) sub-array assignment
- Assigns to each element the value of the corresponding element in sub (sizes shall match).
- (1) copy / move assignment
- Assigns the contents of x to
*thisafter resizing the object (if necessary):
- The copy assignment assigns to each element the value of the corresponding element in x.
- The move assignment acquires the contents of x, leaving x in an unspecified but valid state. - (2) fill assignment
- Assigns val to every element.
The size of the valarray is preserved, with each of its element equal to this value. - (3) sub-array assignment
- Assigns to each element the value of the corresponding element in sub (sizes shall match).
Parameters
- x
- A valarray object of the same type (with the same class template argument T).
- val
- Value assigned to all the elements are in the valarray.
T is the template argument of valarray (the value type). - sub
- The result of a valarray subscripting operation.
T is the template argument of valarray (the value type).
Return value
*this
Example
|
|
Output:
Complexity
Depends on library implementation (operations may be parallelized).Iterator validity
Data races
All copied elements are accessed.The move assignment modifies x.
The object and all its elements are modified.
Exception safety
If any operation performed on the elements throws an exception, it causes undefined behavior.If the function needs to allocate storage and fails, it may throw an exception (such as bad_alloc), although this is not mandated.
The move assignment never throws exceptions (no-throw guarantee).
See also
- valarray::valarray
- valarray constructor (public member function)