1

我正在尝试与仅使用原始指针来保存数据的软件进行交互。shallow_array_adaptor 我非常有信心,如果我制作包装向量实例,我可以避免使用问题,const即使文档shallow_array_adaptor声称它“非常危险!”。

我想做这样的事情:

using namespace boost::numeric::ublas
void f(vector<double>& acc, double* arr){ 
    // assume acc is already correctly sized, and arr is correctly allocated

   // this syntax is not correct, I'm pretty sure I'll have to construct
   // the instance of shallow_array_adaptor, but don't know how  to
   // get it to the vector's constructor 
   const vector< double , shallow_array_adaptor< double > > view( arr );

    acc+=view; // by wrapping the raw pointer, I get to use nice syntax here.
}

无需复制存储在arr.

我不确定我必须做什么来构造向量,以便它使用给定的指针作为存储。

4

0 回答 0