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: [email protected]
       [email protected]

http://ligarto.org/rdiaz

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to