1// Copyright 2002 The Trustees of Indiana University.
2
3// Use, modification and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// Boost.MultiArray Library
8// Authors: Ronald Garcia
9// Jeremy Siek
10// Andrew Lumsdaine
11// See http://www.boost.org/libs/multi_array for documentation.
12
13// foreach_test.cpp
14// Let's see if this stuff works
15
16#include "boost/multi_array.hpp"
17#include "for_each.hpp"
18#include <algorithm>
19
20struct times_five {
21 double operator()(const int& val) { return val*5.0; }
22};
23
24
25int main() {
26
27 typedef boost::multi_array<double,2> array;
28
29 double data[] = {
30 1.0, 2.0, 3.0,
31 4.0, 5.0, 6.0,
32 7.0, 8.0, 9.0
33 };
34 const int data_size=9;
35
36 array A(boost::extents[3][3]);
37 A.assign(begin: data,end: data+data_size);
38
39#if 0
40 std::copy(A.data(),A.data()+A.num_elements(),
41 std::ostream_iterator<double>(std::cout,","));
42
43 std::cout << "\n";
44#endif
45 for_each(A,xform: times_five());
46
47#if 0
48 std::copy(A.data(),A.data()+A.num_elements(),
49 std::ostream_iterator<double>(std::cout,","));
50
51 std::cout << "\n";
52#endif
53 return 0;
54}
55

source code of boost/libs/multi_array/example/foreach_test.cpp