[Rcpp-devel] RcppModules with templated class

Dr Gregory Jefferis jefferis at mrc-lmb.cam.ac.uk
Mon Sep 1 15:58:51 CEST 2014


On 1 Sep 2014, at 14:09, Dirk Eddelbuettel wrote:

> And I think I was trying to explain to you that
> - becase _R_ only knows double and
> - does dispatch by _name_ only
> there is no clean way in which _Rcpp_ can maintain these as two 
> distinct
> versions under the same name.  In short, just because you can template 
> at the
> C++ level does not mean that Rcpp can shoehorn both variants up to
> R-accessibility.

OK either, I'm being dense or it looks Like I still wasn't clear (or 
both!). I have:

a templated C++ class (WKNN)
typedefs for T=double (WKNND) and T=float (WKNNF)
RCppModules wrappers for WKNND and WKNNF for R producing separate R 
reference classes with _different_ names.  Here is a stripped down 
version of the code:

template<typename T>
struct WKNN {
   public:
   WKNN(const Eigen::Map<Eigen::MatrixXd> data, bool buildtree=true);
   // other methods ...
   private:
   Eigen::Matrix<T, Dynamic, Dynamic> data_pts;
}

typedef WKNN<double> WKNND;

RCPP_MODULE(class_WKNND) {
   class_<WKNND>( "WKNND" )
   .constructor<Eigen::Map<Eigen::MatrixXd> >()
   // other methods ...
   ;
}

typedef WKNN<float> WKNNF;

RCPP_MODULE(class_WKNNF) {
   class_<WKNNF>( "WKNNF" )
   .constructor<Eigen::Map<Eigen::MatrixXd> >()
   // other methods ...
   ;
}

Do you see any reason why this shouldn't be workable with RcppModules? 
The only thing that is odd is that I have:

template<typename T>
struct WKNN

not

template<typename T>
class WKNN

because you can't seem to do this:

typedef WKNN<float> WKNNF;

when using the class keyword rather than struct. But perhaps this is the 
origin of the problem – i.e. if RcppModules somehow depends 
specifically on the use of the class keyword even though struct should 
be equivalent (apart from default access rules). I believe that you can 
directly typedef a class in C++11 so perhaps I should be insisting on 
C++11.

Many thanks again for your input,

Greg.

--
Gregory Jefferis, PhD                   Tel: 01223 267048
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://flybrain.stanford.edu


More information about the Rcpp-devel mailing list