[Rcpp-devel] Inline, templates, and easy debugging

John Merrill john.merrill at gmail.com
Thu Nov 22 03:59:54 CET 2012

tl;dr summary -- is there a way to incorporate multiple functions into
an inline call?  Specifically, is there a way to include a templated
function in an inline compilation?

Consider the following outline:

template <typename T>
void InsertTypedVector<const T& src, T* dest) {
  < stuff >

RcppExport SEXP ExposedFunction(SEXP r_foobar) {
  DataFrame df(r_foobar);

  for (int i = 0; i < df.size(); ++i) {
    RObject current_robj=df(i);

    switch (TYPEOF(current_robj)) {
      case CHARSXP:
         StringVector current_str = current_robj;



     case REALSXP:
          NumericVector current_num = current_robj;



The point of this code is that I'm trying to write a function which
does the homologous thing to each column of a dataframe in a
type-sensitive way -- treating strings as strings, reals as reals,
complex values as complex values, etc.  That's cool, and it's what C++
is written to support.

Here's the problem: in order to compile this, I need it to be in a
package.  Now, obviously, since I'm building a package, that is no
problem in itself.  What I want to be able to do is DEVELOP this kind
of code in Inline, and then transform it into package code after I'm
done debugging it.

Compiling this using inline is not trivial: embedded classes are not
allowed to contain templated functions, so I can't hack the generic
function in as a static or dynamic member function inside the body of
the function I provide as an argument to inline.

Is there a way to do this using inline?

More information about the Rcpp-devel mailing list