开发者

how to merge two or more one dimensional boost::multi_array s?

I want to learn how to add an one dimensional multi_ar开发者_Go百科ray to end of another one dimensional multi_array. How would i do that?


Boost multi-array has (not very well documented) iterators like any other container, so you can use them as normal.

#include <boost/multi_array.hpp>
#include <iostream>

int
main  (int ac, char **av)
{
  typedef boost::multi_array<int, 1> array_type;
  array_type::extent_gen extents;
  //create some arrays
  array_type A(extents[3]);
  array_type B(extents[2]);
  //assign values
  A[0] = 4;
  A[1] = 3;
  A[2] = 5;
  B[0] = 1; 
  B[1] = 2;
  //resize A, (copies original values)  
  A.resize(extents[A.size()+B.size()]);
  //use iterators for copying
  std::copy(B.begin(), B.end(), A.end()-B.size());
  //check the output.
  for(size_t i=0;i<A.size();++i){
    std::cout<<A[i]<<std::endl;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜