[Rcpp-devel] Rcpp::Dimension initialized from an SEXP
Douglas Bates
bates at stat.wisc.edu
Sat May 8 16:21:42 CEST 2010
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.
-------------- next part --------------
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)
More information about the Rcpp-devel
mailing list