cplusplus.com
C++ : Reference : Miscellaneous : valarray : valarray : valarray
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
valarray
classes:
gslice
gslice_array
indirect_array
mask_array
slice
slice_array
valarray
global functions:
abs
acos
asin
atan
atan2
cos
cosh
exp
log
log10
pow
sin
sinh
sqrt
tan
tanh
valarray
valarray operators
valarray::valarray
valarray::~valarray
member functions:
valarray::apply
valarray::cshift
valarray::max
valarray::min
valarray::operator=
valarray::operator[]
valarray::resize
valarray::shift
valarray::size
valarray::sum


valarray::valarray

public member function
valarray();
explicit valarray (size_t n);
valarray (const T& val, size_t n);
valarray (const T* p, size_t n);
valarray (const valarray& x);
valarray (const slice_array<T>& sub);
valarray (const gslice_array<T>& sub);
valarray (const mask_array<T>& sub);
valarray (const indirect_array<T>& sub);

valarray constructor

Constructs a valarray object.

Parameters

n
Length of array.
If this is the only parameter, the elements are constructed with their default constructor.
size_t is an unsigned integral type.
val
Value to which each of the elements is initialized.
T is the template type of valarray (the elements' type).
p
Pointer to an array of elements. The first n elements are used as initial values for the elements in the valarray.
T is the template type of valarray (the elements' type).
x
A valarray object.
The elements in *this are initialized to copies of the elements in x. The resulting length matches that of x.
sub
The result of a valarray subscripting operation.
The elements in *this are initialized to copies of the elements in sub. The resulting length matches that of sub.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// valarray constructor example
#include <iostream>
#include <valarray>
using namespace std;

int main ()
{
  int init[]= {10,20,30,40};
  valarray<int> first;           // (empty)
  valarray<int> second (5);      // 0 0 0 0 0
  valarray<int> third (10,3);    // 10 10 10
  valarray<int> fourth (init,4); // 10 20 30 40
  valarray<int> fifth (fourth);  // 10 20 30 40

  cout << "fifth sums " << fifth.sum() << endl;

  return 0;
}


Output:

fifth sums 100

See also