|
Boost Users : |
Subject: [Boost-users] c++: boost::multi_array - initialize a multi_array
From: Hannan Sadar (hannan.sadar_at_[hidden])
Date: 2009-12-29 09:52:40
Hi all,
i am trying to initialize all the elements in boost::multi_array type to
zero, so far, with out success. At tried using std::fill for 1-dim
boost::multi_array and it worked. Once i tried std:fill on 2-dim
boost::multi_array it haven't worked any more.
I saw boost have
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assert.hpp>;
libraries but i don't know if this is the correct way to initialize a 2-dim
multi_array.
I would like to know how to initialize a boost::multi_array in an elegant
way.
here is an example code of my multi_array (it pass compilation, but return
an error at run time):
#include <iomanip>
#include "boost/multi_array.hpp"
#include <iostream>
namespace vec {
typedef boost::multi_array<unsigned int, 1> uint_1d_vec_t;
typedef boost::multi_array<unsigned int, 2> uint_2d_vec_t;
typedef uint_1d_vec_t::index index_1d_t;
typedef uint_2d_vec_t::index index_2d_t;
}
int main( ) {
unsigned int num_elements, num_bits, max_runs, m;
num_bits = 12;
max_runs = 5000;
m = 2;
num_elements = ( 1 << num_bits );
int kappa = 79;
vec::uint_1d_vec_t foo( boost::extents[ static_cast< vec::index_1d_t
>(num_elements) ] );
vec::uint_2d_vec_t boo( boost::extents[ static_cast< vec::index_2d_t
>(num_elements) ][ static_cast< vec::index_2d_t >(kappa) ] );
std::fill( foo.begin() , foo.end() , 0);
std::fill( boo.begin()->begin() , boo.end()->end() , 0);
std::cout << "Done" << std::endl;
return EXIT_SUCCESS;
}
any suggestion is welcome
regards
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net