Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting boost multi_array to its native array type

I am writing a class that acts as a go-between for c++ classes and legacy c code. I have been using boost multi_array's to simplify a lot of the code. This mult_array is declared as such:

using Array = boost::multi_array<float,2>

However, I have run into a problem where I need to pass my multi_array to a legacy function that has a signature similar to

void function(float param[ROWS][COLS]);

My multi_array is of size ROWS and COLS, but I do not know of any easy way to convert the mutli_array to an array. Is there any way to do so?

like image 299
CodeSmith Avatar asked Nov 30 '25 16:11

CodeSmith


1 Answers

Since the storage order of boost::multi_array is well defined, you can actually call it safely like that:

function((float (*)[COLS])array.data());

c_storage_order is the default, make sure to not use anything else upon construction of the object.

like image 83
Zulan Avatar answered Dec 02 '25 05:12

Zulan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!