define multi dimension array at run time

Hello list I'm writing an n-dimensional histogram class and would like to use the boost multidimension array to store the elements of the histogram So the array is defined as a class member but is first initialized through the constructor, but according to boost example page its something like: typedef boost::multi_array<double, 3> array_type; but I'd like: typedef boost::multi_array<std::vector<MyObject>, n> array_type; where n is given through the constructor Is this somehow possible? Regards Moataz

Hi Moataz,
So the array is defined as a class member but is first initialized through the constructor, but according to boost example page its something like: typedef boost::multi_array<double, 3> array_type;
but I'd like: typedef boost::multi_array<std::vector<MyObject>, n> array_type; where n is given through the constructor
Is this somehow possible?
You can't change the dimensionality of a multi_array at runtime. You could write templated logic for N dimensional instances, instantiate up to some maximum (say 42), and then manage those with some common facade. This won't be pretty... - Rhys

On 06/08/12 16:54, Rhys Ulerich wrote:
Hi Moataz,
So the array is defined as a class member but is first initialized through the constructor, but according to boost example page its something like: typedef boost::multi_array<double, 3> array_type;
but I'd like: typedef boost::multi_array<std::vector<MyObject>, n> array_type; where n is given through the constructor
Is this somehow possible?
You can't change the dimensionality of a multi_array at runtime.
You could write templated logic for N dimensional instances, instantiate up to some maximum (say 42), and then manage those with some common facade. This won't be pretty...
- Rhys
The subject: Subject: Re: RFC: runtime-flexible arrays from this post: http://article.gmane.org/gmane.comp.lib.boost.devel/228269/match=runtime+fle... suggests that thread might have some useful ideas on the subject. HTH. -regards, Larry
participants (3)
-
Larry Evans
-
Moataz Elmasry
-
Rhys Ulerich