你如何使用shallow_array_adaptor

时间:2013-01-29 17:52:25

标签: c++ pointers boost

我正在尝试与仅使用原始指针来保存数据的软件进行交互。 我非常有信心可以避免使用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中存储的值。

我不确定我要做什么来构建它使用的向量 给定指针作为存储。

0 个答案:

没有答案
相关问题