Computer language design is just like a stroll in the park. Jurassic Park, that is. Larry Wall
Valarray hold the array of elements which used in mathematical operations.
![]() |
A valarray object is designed to hold an array of values, and easily perform mathematical operations. |
![]() |
Represent and manipulate array of values. |
![]() |
Valarray is a dynamic data structure and supports variable length of items. |
![]() |
Valarray has an interface to retrieve slices of the array. |
![]() |
Support optimizations techniques known as expression templates. |
#include "stdafx.h" #include < iostream > #include < valarray > using namespace std; int _tmain(int argc, _TCHAR* argv[]) { valarray < int > valarray(10); cout << "Store items from 0 to 10 in the valarray" << endl; for (int i = 0; i < 10; i++) { valarray[i] = i; } cout << "Print items from valarray: "; for (int i = 0; i < 10; i++) { cout << valarray[i] << " "; } cout << endl<< "min() of valarray itmes: " << valarray.min() << endl; cout << "max() of valarray itmes: " << valarray.max() << endl; cout << "sum() of valarray itmes: " << valarray.sum() << endl; cout << endl; return 0; }
Store items from 0 to 10 in the valarray Print items from valarray: 0 1 2 3 4 5 6 7 8 9 min() of valarray itmes: 0 max() of valarray itmes: 9 sum() of valarray itmes: 45
The valarray array classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized.
0 Comments