The enclosed section of code using Rcpp::Dimension fails to compile
because of the const qualifiers for the simple::nrow and simple::ncol
method functions. If you omit those const qualifiers then it will
compile and behave as desired. Of course, I would prefer to have
those method functions use the const qualifier. Does anyone have
suggestions on how to modify this code so I can use the const
qualifiers?
My guess is that this is related to the Rcpp::Dimension::operator[]()
returning an int& and not an int so somehow there is a delayed
evaluation going on - but I haven't learned enough C++ to be able to
decide exactly where the problem originates.
library(inline)
cdef <- '
class simple {
Rcpp::Dimension dd;
public:
simple(SEXP xp) : dd(xp) {}
int nrow() const { return dd[0]; }
int ncol() const { return dd[1]; }
};
'
cpp <- '
simple ss(ia);
return Rcpp::wrap(ss.nrow());
'
ff <- cfunction(signature(ia = "integer"), cpp, Rcpp = TRUE, includes = cdef)
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel