[Rcpp-devel] template functions with Rcpp

daniel castro danielcastrob at gmail.com
Sat May 2 07:31:10 CEST 2015


Hello,

I'm trying to build a function that calculates (for example) the log
of all elements of a container. I want this container to be a vector,
a Rcpp::numericVector , or perhaps a arama::colvec , so I'm trying
with templates ,and it compiles without the // [[Rcpp::export]] part,
but when I put it to export to R it doesn't work:

//declaration
template<class T>
T Vlog(T vectorForm);

//code
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
template<class T>
T Vlog(T vectorForm)
{


   std::transform(vectorForm.begin(), vectorForm.end(),
vectorForm.begin(), log);
   return vectorForm;
}


gives 'T' was not declared in this scope.

if possible, How could I fix it?

Thank you in advance
Daniel,


More information about the Rcpp-devel mailing list