Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
indirect_array.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <valarray.h> // Includes valarray and provides stream inserter.
31#include <examples.h> // Generic header for all examples.
32
33typedef std::valarray<int> valarray_t;
34typedef std::valarray<std::size_t> selector_t;
35
36int main(void) {
37
38 // Create a valarray of integers.
39 valarray_t::value_type vbuf[10] = {0,1,2,3,4,5,6,7,8,9};
40 valarray_t vi(vbuf, (sizeof vbuf / sizeof *vbuf));
41
42 // Create a valarray of indices for a selector.
43 selector_t::value_type sbuf[6] = {0,2,3,4,7,8};
44 selector_t selector(sbuf, (sizeof sbuf / sizeof *sbuf));
45
46 // Print out the valarray<int>.
47 std::cout << "original valarray vi\n\n" << vi << "\n\n";
48
49 // Print out the selective array.
50 std::cout << "vi[0,2,3,4,7,8]\n\n" << vi[selector] << "\n\n";
51
52 // Double the selected values.
53 vi[selector] += vi[selector];
54
55 // Print out the modified valarray.
56 std::cout << "vi[0,2,3,4,7,8] += vi[0,2,3,4,7,8]\n\n" << vi << std::endl;
57
58 return 0;
59}
60
std::valarray< std::size_t > selector_t
Definition gslice.cpp:34
std::valarray< int > valarray_t
Definition gslice.cpp:33
std::valarray< std::size_t > selector_t
int main(void)
std::valarray< int > valarray_t