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 | |
---|
14 | #include "boost/multi_array.hpp" |
---|
15 | #include "boost/cstdlib.hpp" |
---|
16 | |
---|
17 | int |
---|
18 | main() |
---|
19 | { |
---|
20 | using boost::extents; |
---|
21 | using boost::indices; |
---|
22 | typedef boost::multi_array<int,3> array; |
---|
23 | |
---|
24 | int data[] = { |
---|
25 | 0,1,2,3, |
---|
26 | 4,5,6,7, |
---|
27 | 8,9,10,11, |
---|
28 | |
---|
29 | 12,13,14,15, |
---|
30 | 16,17,18,19, |
---|
31 | 20,21,22,23 |
---|
32 | }; |
---|
33 | const int data_size=24; |
---|
34 | |
---|
35 | array myarray(extents[2][3][4]); |
---|
36 | myarray.assign(data,data+data_size); |
---|
37 | |
---|
38 | // |
---|
39 | // array_view dims: |
---|
40 | // [base,stride,bound) |
---|
41 | // [0,1,2), [1,1,3), [0,2,4) |
---|
42 | // |
---|
43 | |
---|
44 | typedef boost::multi_array_types::index_range range; |
---|
45 | array::array_view<3>::type myview = |
---|
46 | myarray[indices[range(0,2)][range(1,3)][range(0,4,2)]]; |
---|
47 | |
---|
48 | for (array::index i = 0; i != 2; ++i) |
---|
49 | for (array::index j = 0; j != 2; ++j) |
---|
50 | for (array::index k = 0; k != 2; ++k) |
---|
51 | assert(myview[i][j][k] == myarray[i][j+1][k*2]); |
---|
52 | |
---|
53 | return boost::exit_success; |
---|
54 | } |
---|