public member function
<valarray>
valarray<T>& operator=(const valarray<T>& x);
valarray<T>& operator=(const T& val);
valarray<T>& operator=(const slice_array<T>& sub);
valarray<T>& operator=(const gslice_array<T>& sub);
valarray<T>& operator=(const mask_array<T>& sub);
valarray<T>& operator=(const indirect_array<T>& sub);
Assign content
Assigns content to
valarray object.
The first constructor (copy constructor), assigns to each element the value of its corresponding element in
x - the behavior is unspecified if sizes do not match.
The second constructor assigns to all the elements in the array the value
val.
The remaining constructors assign the result of the subscriptiong operation
sub to the
valarray object.
Parameters
- x
- Another valarray. The values of its elements are copied to their corresponding elements in the object.
The behavior when lengths do not match in unspecified - depends on the library implementation.
- val
- All the elements are in the valarray are set to this value.
The length of the valarray is preserved, with each of its element equal to this value.
T is the template type of valarray (the elements' type).
- sub
- The result of a valarray subscripting operation.
Return value
*this
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// valarray assignment example
#include <iostream>
#include <valarray>
using namespace std;
int main ()
{ // foo: bar:
valarray<int> foo (4); // 0 0 0 0
valarray<int> bar (2,4); // 0 0 0 0 2 2 2 2
foo = bar; // 2 2 2 2 2 2 2 2
bar = 5; // 2 2 2 2 5 5 5 5
foo = bar[slice (0,4,1)]; // 5 5 5 5 5 5 5 5
cout << "foo sums " << foo.sum() << endl;
return 0;
}
|
Output:
See also
- valarray::valarray
- valarray constructor (public member function)