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