On 22 November 2012 at 16:42, Romain Francois wrote: | Le 22/11/12 16:25, Hadley Wickham a écrit : | >> #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 | | Unfortunately, there is not. The issue is that we don't know the type of | x at compile type, so we have to do this switch dance and trigger | explicit instanciations of all method<> overloads.
It's one of those times were we get reminded that using C has limitations. To the compiler SEXP is just one type, and the dispathing on the 'union type' is done at run-time, not compile time as one could via templates. | There is no other way I know about. Switch to Andrew Runnall's CXXR :) Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel