Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.MultiArray]: size question
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-12-17 12:24:24


On 12/17/12 09:50, gast128 wrote:
> Dear all,
>
> we use here the multi_array as a 2 dimensional matrix. Often we want to resize
> the row or column dependent on some GUI event. Code could be:
>
> void Bla::ResizeRows(size_t nRows)
> {
> m_matrix.resize(boost::extents[nRows][m_matrix[0].size()]);
> }
>
> However this uses the 0-index of row count (i.e. 'm_matrix[0].size()') to
> determine the size of the columns. Will this not crash if you have 0 rows? And
> if so is there a better alternative?
>
> wkr.
The test driver:

http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/array_dyn/array_dyn.cpp

produces output:

********reshape demo***********
dir_op=0
shape={ 0, 3}
my_data.size()=0
ai=
}
.
shape={ 1, 3}
ai=
{ { 0, 0, 0}
}
.
shape={ 5, 3}
ai=
{ { 0, 0, 0}
, { 0, 0, 0}
, { 0, 0, 0}
, { 0, 0, 0}
, { 0, 0, 0}
}
.

Compilation finished at Mon Dec 17 11:11:25

Which suggests it will work when 1st axis (the row axis) has 0 as it's
size. Unfortunately, this is not Boost.MultiArray and it's probably
a lot slower since the sizes of the dimensions are all runtime values.
Also, the printout when the shape includes a 0, as in:

  shape={ 0, 3}

does not have balanced curly brackets:

 ai=
 }

I'm not sure how to handle that yet.


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