1

In the comment, it is said that move semantics are not adopted in Rcpp classes. Some developers prefer writing return std::move(x) in all functions when C++11 is enabled just as the following:

NumericVector test(const NumericVector& x) {
  NumericVector y(x.size());
  for (int i = 0; i < x.size(); i++) {
    y[i] = x[i] * 2;
  }
  return std::move(y);
}

I'm wondering if there's any benefit or downside writing Rcpp code like this, or any risk that code runs into trouble if the code is more complex?

Kun Ren
  • 4,715
  • 3
  • 35
  • 50
  • Why not do it a few millions times with vectors of different sizes in a quick benchmark? It could be faster; it could be that the C interface we have to use gets in the way and it is both the same (or slower). Could also depend on the compiler, version and OS. – Dirk Eddelbuettel May 29 '18 at 11:01
  • A series of benchmark with different data size shows very little difference in performance. I'm wondering if there may be any downside about this? – Kun Ren May 29 '18 at 11:23
  • 2
    Might be a good read: https://stackoverflow.com/a/14856553/1794345 – Rerito May 29 '18 at 12:20
  • Spot on, thanks for the link. Could consider it a duplicate, could keep it for the Rcpp crowd. – Dirk Eddelbuettel May 29 '18 at 12:48

0 Answers0