[Rcpp-devel] Dispatching based on SEXPTYPE

Hadley Wickham h.wickham at gmail.com
Thu Nov 22 16:25:42 CET 2012


> #define DISPATCH_METHOD(method, x)  \
>   switch( TYPEOF(x) ){          \
>     case REALSXP:                   \
>       return method<REALSXP>(x);    \
>     case INTSXP:                    \
>       return method<INTSXP>(x);     \
>     case STRSXP:                    \
>       return method<STRSXP>(x);     \
>     case LGLSXP:                    \
>       return method<LGLSXP>(x);     \
>     default:                        \
>       Rf_error("Unsupported type"); \
>       return x;                     \
>   }

Why do we need a macro here? Is it not possible to pass in method as a
function?  It seems like there must be a more elegant way to do
dynamic dispatch.

Hadley


-- 
RStudio / Rice University
http://had.co.nz/


More information about the Rcpp-devel mailing list