#include "boost/multi_array.hpp" //stl #include #include using namespace std; int main(int argc, char **argv){ const int M = 3; const int N = 4; typedef boost::multi_array< int, 2> array_t; typedef array_t::index index; typedef array_t::index_range range_t; typedef array_t::array_view<1>::type array_1d_view_t; array_t A( boost::extents[M][N], boost::fortran_storage_order() ); int num = 0; for ( index i = 0; i < M ; ++i ) { for ( index j = 0; j < N ; ++j ) { A[i][j] = ++num; } } cout << "A: 3x4 array" << endl; for ( index i = 0; i < M ; ++i ) { for ( index j = 0; j < N ; ++j ) { cout << A[i][j] << "\t"; } cout << endl; } cout < col( &(col_view[0]), boost::extents[M], boost::fortran_storage_order() ); cout << endl << "It's third column is:" << endl; for ( boost::multi_array_ref< int, 1>::iterator rowIt = col.begin(); rowIt != col.end(); ++rowIt ) { cout << *(rowIt) << endl; } array_1d_view_t row_view = A[ boost::indices[2][range_t(0,N)] ]; boost::multi_array_ref< int, 1> row( &(row_view[0]), boost::extents[N], boost::fortran_storage_order() ); cout << endl << "It's third row is:" << endl; for ( boost::multi_array_ref< int, 1>::iterator colIt = row.begin(); colIt != row.end(); ++colIt ) { cout << *(colIt) << "\t"; } cout << endl; return 1; } int wmain(int argc, char **argv) { return main(argc, argv); }