Help with boost::multi_array

Started by
3 comments, last by pLikT 17 years, 6 months ago
Is there a way to be able to set the number of dimensions for boost::multi_array during run time?

//test.h
#pragma warning( disable : 4267 ) //truncation from size_t to int in multi_array
#pragma warning( disable : 4996 ) //_Fill_n declared deprecated

#include <boost/multi_array.hpp>
using boost::multi_array;

class TestClass
{
public:
	TestClass( int = 1 );

	const int array_dimensions;
	multi_array< double, array_dimensions > an_array; //Error 1 and 2
};

TestClass::TestClass( int inDimensions )
: array_dimensions( inDimensions )
{} //Error 3

//Errors
~\project\marray.h(14) : error C2327: 'TestClass::array_dimensions' : is not a type name, static, or enumerator
~\project\marray.h(14) : error C2065: 'array_dimensions' : undeclared identifier
~\project\marray.h(19) : error C2512: 'boost::multi_array' : no appropriate default constructor available

Advertisement
Bump?

If boost::multi_array only allows static multi-dimensional arrays, is there something out there that encapsulates a dynamic version?
How are you planning to use an array where you don't know how many *dimensions* it has? O_O The boost::multi_array is quite 'dynamic': the number of dimensions, and the element type, are the only things that have to be worked out at compile time, and that's really as good as you can get. You certainly can resize each dimension at will (subject to available memory).

What are you trying to do?
You could make the TestClass a templated class with a "number of dimensions" argument. Then you could generate all the 5000 versions of the class using the boost preprocessor. I can't imagine any other way to do this using boost::multiarray. You could try faking the multiple dimensions with a single dimension array and use an indexing formula, but this formula could get rather complicated with variable number of dimensions. What are you trying to do, maybe there is a better solution?
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
I'm creating a class that represents an area of space in which you can add or remove objects. Ie. 1d space that spans 0 to 100 and is separated into 4 groups (0-25, 26-50, 51-75 and 76-100 ). You can add an object that spans 45 to 55 and later find out that the object exists somewhere within the middle two groups but not the outer two.

The class works fine with one dimension, but later I found out that I need a 2d container( or concept ) if I wanted to work with two dimensions or an n-dimension container for n dimensions. Thus my question.

I know there's dimension indepdendent code in accessing elements( straight from the reference ). I was just wondering if I was missing something that makes the initialization dimension independent.

If nothing's available, I can just create a different class for each dimension I use.

This topic is closed to new replies.

Advertisement