[Rcpp-devel] templated NA
Le 23/06/11 20:48, Andrew Redd a ?crit :
Is there a templated version of NA with Rcpp, or perhaps some sugar statement, such that the following might be valid statements? typedef double mytime; const mytime time_unknown = Rcpp::NA<mytime>; Thanks, Andrew
You might get what you want using a combination of the traits::get_na
and traits::r_sexptype_traits templates.
Something like :
require( Rcpp )
require( inline )
inc <- '
typedef double mtime ;
template <typename T>
inline T NA(){
return traits::get_na< traits::r_sexptype_traits<T>::rtype >() ;
}
'
fx <- cxxfunction( , '
mtime na = NA<mtime>() ;
return wrap( na ) ;
', inc = inc, plugin = "Rcpp" )
fx()
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr http://romain-francois.com |- http://bit.ly/lJoWbH : Montpellier Com?die Club - Juin 2011 |- http://bit.ly/kaSV6U : Stand up set at Up The Creek `- http://bit.ly/hdKhCy : Rcpp article in JSS