[Rcpp-devel] Dispatching based on SEXPTYPE
romain at r-enthusiasts.com
romain at r-enthusiasts.com
Mon Nov 26 21:55:53 CET 2012
We'll probably have something similar in Rcpp at some point.
Le 2012-11-26 21:52, Davor Cubranic a écrit :
> Is this macro intended to be used in other, similar contexts?
> Otherwise, why not have "switch" inside unique2, as in Hadley's
> original code?
>
> Davor
>
>
> On 2012-11-22, at 7:25 AM, Hadley Wickham wrote:
>
>>> #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/
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>>
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
More information about the Rcpp-devel
mailing list