c++ - Boost Multiarray of std::vector -
i'm new boost (and stackoverflow) , want use multiarray of vectors. have done way:
typedef boost::multi_array<std::vector<vector3_t>, 2> array_type; array_type* mimage; int mresolution = 1000; mimage = new array_type (boost::extents[mresolution][mresolution]); //works mimage[0][0].origin()->push_back(vector3_t()); //error: abort() mimage[1][1].origin()->push_back(vector3_t()); //error: abort() mimage[500][440].origin()->push_back(vector3_t());
on internet can find examples of multiarray use int,doule , on. possible use std::vector in mutliarray ? know use 3d multiarray, prefer vectors elemet.
boost.multiarray supports std::vector
elements. in general, boost.multiarray perform concept checking @ compile-time. thus, if code compiles complete type, should supported.
with mimage[0][0].origin()
:
mimage[0][0]
returns referencestd::vector<vector3_t>
.origin()
not member function onstd::vector<vector3_t>
, resulting in error.
origin()
member function of multi-array, returns address of first element's storage. in case array has not been reindexed positive index, equivalent of 0
indexes (i.e. mimage.origin() == &mimage[0][0]
).
here brief , complete example multi-array of vector of vector of ints.
#include <iostream> #include <vector> #include <boost/foreach.hpp> #include <boost/range/counting_range.hpp> #include <boost/multi_array.hpp> int main() { typedef std::vector<int> vector3_type; typedef boost::multi_array<std::vector<vector3_type>, 2> array_type; array_type array(boost::extents[5][5]); // insert vector multi-array. array[0][0].push_back(vector3_type()); // insert range of [100,105) first vector @ [0][0] boost_foreach(const int& i, boost::counting_range(100, 105)) array[0][0].front().push_back(i); // print integers @ [0][0][0] boost_foreach(const int& i, array[0][0][0]) std::cout << << std::endl; }
and running produces following expected output:
100 101 102 103 104
Comments
Post a Comment