valarray::valarray
Constructs a valarray of a specific size or with elements of a specific value or as a copy of another valarray or subset of another valarray.
valarray( );
explicit valarray(
size_t _Count
);
valarray(
const Type& _Val,
size_t _Count
);
valarray(
const Type* _Ptr,
size_t _Count
);
valarray(
const valarray<Type>& _Right
);
valarray(
const slice_array<Type>& _SliceArray
);
valarray(
const gslice_array<Type>& _GsliceArray
);
valarray(
const mask_array<Type>& _MaskArray
);
valarray(
const indirect_array<Type>& _IndArray
);
Parameters
_Count
The number of elements to be in the valarray._Val
The value to be used in initializing the elements in the valarray._Ptr
Pointer to the values to be used to initialize the elements in the valarray._Right
An existing valarray to initialize the new valarray._SliceArray
A slice_array whose element values are to be used in initializing the elements of the valarray being constructed._GsliceArray
A gslice_array whose element values are to be used in initializing the elements of the valarray being constructed._MaskArray
A mask_array whose element values are to be used in initializing the elements of the valarray being constructed._IndArray
A indirect_array whose element values are to be used in initializing the elements of the valarray being constructed.
Return Value
The first (default) constructor initializes the object to an empty array. The next three constructors each initialize the object to an array of count elements as follows:
For explicit valarray(size_t _Count), each element is initialized with the default constructor.
For valarray(const Type& _Val, _Count), each element is initialized with _Val.
For valarray(const Type* _Ptr, _Count), the element at position I is initialized with _Ptr[I].
Each remaining constructor initializes the object to a valarray<Type> object determined by the subset specified in the argument.
Example
// valarray_ctor.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
// The second member function
valarray<int> va ( 10 );
for ( i = 0 ; i < 10 ; i += 1 )
va [ i ] = 2 * ( i + 1 );
cout << "The operand valarray va is:\n(";
for ( i = 0 ; i < 10 ; i++ )
cout << " " << va [ i ];
cout << " )" << endl;
slice Slice ( 2 , 4 , 3 );
// The fifth member function
valarray<int> vaSlice = va [ Slice ];
cout << "The new valarray initialized from the slice is vaSlice ="
<< "\nva[slice( 2, 4, 3)] = (";
for ( i = 0 ; i < 3 ; i++ )
cout << " " << vaSlice [ i ];
cout << " )" << endl;
}
The operand valarray va is:
( 2 4 6 8 10 12 14 16 18 20 )
The new valarray initialized from the slice is vaSlice =
va[slice( 2, 4, 3)] = ( 6 12 18 )
Requirements
Header: <valarray>
Namespace: std