Boost logo

Boost Users :

Subject: Re: [Boost-users] Can I delete/resize a multi_array??
From: Ramon F Herrera (ramon_at_[hidden])
Date: 2011-02-28 12:22:19


On 2/28/2011 10:53 AM, Jeff Flinn wrote:
> Ramon F Herrera wrote:
>>
>> I recently discovered the multi_array, which was the answer to my
>> prayers:
>>
>> typedef boost::multi_array<string, 2> ExpressionArrayType;
>> ExpressionArrayType exprTable(boost::extents[extreme_row][extreme_col]);
>>
>> But now I need more functionality, which can be either:
>>
>> (1) Erase the current "exprTable" and create a new one, with different
>> dimensions.
>
> Do you mean different dimensionality? The dimensionality is part of the
> type and determined at compile time. Different dimensionality requires a
> different type.
>
>> (2) Resize the current dimensions.
>
> Doesn't this explain resizing?
>
> http://www.boost.org/doc/libs/1_44_0/libs/multi_array/doc/user.html#sec_resize
>
>
> Jeff

Thanks, Jeff!

The snippet below is along the lines of what I am trying to accomplish.
I read in TFM :-) that there is a destroy method (?), but I have never
need those (until now).

-Ramon

--------------

#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/multi_array.hpp>

using namespace std;

typedef boost::multi_array<string, 2> ExpressionArrayType;

void
new_array(int rows, int cols)
{
  ExpressionArrayType exprTable(boost::extents[rows][10-rows]);
  cout << "size is: " << exprTable.size() << "x" << exprTable[0].size()
<< endl;
}

int
main(int argc, char *argv[])
{
     for (int row = 1; row < 8; row++) {
         new_array(row, row);
     }
     return 0;
}


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