Rcpp and move semantic

被刻印的时光 ゝ 提交于 2019-12-22 08:18:06

问题


I implemented an algorithm in C++ that returns as output a huge array of elements. Now, I would like to implement a wrapper in Rcpp so that I will be able to call this function by using R.

I specified in the Makevars file the following setting:

PKG_CXXFLAGS = -std=c++11

So that I can use the C++11 version.

// [[Rcpp::export]]
NumericMatrix compute(int width, int height)
{
  vector<data_t> weights(width * height);
  compute_weights(weights);

  NumericMatrix mat(height, width);
  copy(begin(weights), end(weights), mat.begin());

  return mat;
}

The above wrapper function remains efficient if the NumericMatrix is moved when returned by the function, otherwise a new object will be created.

Does Rcpp exploit the move semantics? And if not, are there any workarounds to avoid the construction of the copy?

来源:https://stackoverflow.com/questions/33507105/rcpp-and-move-semantic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!