[Rcpp-devel] "const" not allowed for Matrix arguments?

Ramon Diaz-Uriarte rdiaz02 at gmail.com
Fri Nov 16 19:53:21 CET 2012


More on const arguments:

the first will compile and work, the second will not compile, even if we
do not modify anything. As far as I can tell, in this case the culprit is
related to having the reference to the Column, because f3 does compile and
work.

I guess the problem is the "*this", returned by Column; is there another
way of making sure the caller does not modify the matrix, while enjoying
the usage of Column (and Row)?

Best,

R.


// [[Rcpp::export]]
int f1(Rcpp::IntegerMatrix m1) {
  const Rcpp::IntegerMatrix::Column c1 = m1(_, 1);
  int dd = c1[0] * 2;
  return dd;
}

// [[Rcpp::export]]
int f2(const Rcpp::IntegerMatrix m1) {
  const Rcpp::IntegerMatrix::Column c1 = m1(_, 1);
  int dd = c1[0] * 2;
  return dd;
}

// [[Rcpp::export]]
int f3(const Rcpp::IntegerMatrix m1) {
  int dd = m1(0, 0) * 2;
  return dd;
}


-- 
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-25
Facultad de Medicina 
Universidad Autónoma de Madrid 
Arzobispo Morcillo, 4
28029 Madrid
Spain

Phone: +34-91-497-2412

Email: rdiaz02 at gmail.com
       ramon.diaz at iib.uam.es

http://ligarto.org/rdiaz



More information about the Rcpp-devel mailing list