|
Boost Users : |
Subject: Re: [Boost-users] [Boost.MultiArray]: size question
From: Vitaly Budovski (vbudovski+news_at_[hidden])
Date: 2012-12-17 19:44:29
On 18 December 2012 08:24, gast128 <gast128_at_[hidden]> wrote:
> I am talking about multi_array, see title. Example code:
>
> void f()
> {
> typedef boost::multi_array<int, 2> Matrix;
>
> Matrix m1(boost::extents[2][3]);
> _ASSERT(m1.size() == 2);
> _ASSERT(m1[0].size() == 3);
>
> m1.resize(boost::extents[0][3]);
> _ASSERT(m1.size() == 0);
> //_ASSERT(m1[0].size() == 3); //<--assert
> }
>
>
Hi,
The shape function has the list of multi_array dimensions.
This should do it:
#include <boost/multi_array.hpp>
#include <cassert>
int main()
{
typedef boost::multi_array<int, 2> Matrix;
Matrix m1(boost::extents[2][3]);
assert(m1.shape()[0] == 2);
assert(m1.shape()[1] == 3);
m1.resize(boost::extents[0][3]);
assert(m1.shape()[0] == 0);
assert(m1.shape()[1] == 3);
return 0;
}
Cheers,
Vitaly
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