[Rcpp-devel] Deriving type information

Kevin Ushey kevinushey at gmail.com
Fri Feb 14 00:49:48 CET 2014


Hi Søren,

You want to use Rcpp's traits. I don't think these are explicitly
documented anywhere, although there are a few examples on the gallery
demonstrating their usage (e.g.
http://gallery.rcpp.org/articles/top-elements-from-vectors-using-priority-queue/)

In this case, you can use

    traits::storage_type<RTYPE>::type

to extract the type. Typically, using a typedef makes it easiest, so I
would write something like:

    typedef typename traits::storage_type<RTYPE>::type storage_t;
    storage_t a = x[0];

Once you understand the general pattern, it's pretty easy to just read
and understand the traits available at
https://github.com/RcppCore/Rcpp/tree/master/inst/include/Rcpp/traits,
but perhaps this would be a good gallery post.

For more information, I thought this was a pretty good introductory
article on understanding C++ traits:
http://accu.org/index.php/journals/442

Cheers,
Kevin


More information about the Rcpp-devel mailing list