• 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 <iostream>
15 #include "boost/multi_array.hpp"
16 #include "boost/array.hpp"
17 #include "boost/cstdlib.hpp"
18 
19 template <typename Array>
print(std::ostream & os,const Array & A)20 void print(std::ostream& os, const Array& A)
21 {
22   typename Array::const_iterator i;
23   os << "[";
24   for (i = A.begin(); i != A.end(); ++i) {
25     print(os, *i);
26     if (boost::next(i) != A.end())
27       os << ',';
28   }
29   os << "]";
30 }
print(std::ostream & os,const double & x)31 void print(std::ostream& os, const double& x)
32 {
33   os << x;
34 }
main()35 int main()
36 {
37   typedef   boost::multi_array<double, 2> array;
38   double values[] = {
39     0, 1, 2,
40     3, 4, 5
41   };
42   const int values_size=6;
43   array A(boost::extents[2][3]);
44   A.assign(values,values+values_size);
45   print(std::cout, A);
46   return boost::exit_success;
47 }
48 
49 //  The output is:
50 // [[0,1,2],[3,4,5]]
51