<div dir="ltr"><div>Dear All,<br><br>I am trying to deploy a way to enable user extensions for a package that uses Rcpp. In that sense, I have found a vignette from dplyr package ("Hybrid Evaluation") where it is used CRTP.<br><br>Thus, I am trying to reproduce e toy example of that to be exposed by Rcpp Modules. Digging on the matter I found about the package RcppAnnoy which have partially solved the issue. But, I still have a question: How to have different implementations one for each Derived classes exposed by the Rcpp Modules, specifically, how to expose the CRTP interface?<br><br>Following you can find What I did up to the moment. I also read an recent thread in stackoverflow where Dirk mentioned RcppAnnoy but, I can't find the way to expose the especializations.<br><br>Many thanks in advance for your help over that. By the way, I would be glad with any comment or suggestion to fullfill the requirements for the CTRP. even out of the scope of the Modules.<br><br></div>[CODE:]<br><br><br>#include <Rcpp.h><br><br>template < class Derived ><br>class Base {<br><br>  public :<br>  <br>    Base< Derived > ( void ) { } ;<br>    virtual ~Base< Derived > ( void ) { } ;<br>    <br>    // CRTP interface<br>    virtual double operation ( void )<br>      { return static_cast< Derived * >( this ) -> implementation ( ) ; }<br>    <br>  private :<br>    <br>} ;<br><br>class Multiply : public Base< Multiply > {<br><br>  public :<br>  <br>    Multiply ( double, double ) ;<br>    <br>    double implementation ( void ) ;<br>  <br>  private :<br>  <br>    double x, y ;<br><br>} ;<br><br>class Sum : public Base< Sum > {<br><br>  public :<br>  <br>    Sum ( double, double ) ;<br>    <br>    double implementation ( void ) ;<br>  <br>  private :<br>  <br>    double x, y ;<br><br>} ;<br><br>Multiply::Multiply ( double x_, double y_ ) : x ( x_ ), y ( y_ ) { }<br><br>double Multiply::implementation ( void ) { return x * y ; }<br><br>Sum::Sum ( double x_, double y_ ) : x ( x_ ), y ( y_ ) { }<br><br>double Sum::implementation ( void ) { return x + y ; }<br><br>RCPP_EXPOSED_CLASS_NODECL( Base< Multiply > )<br>RCPP_EXPOSED_CLASS_NODECL( Base< Sum > )<br>RCPP_EXPOSED_CLASS( Multiply )<br>RCPP_EXPOSED_CLASS( Sum )<br><br>RCPP_MODULE( CRTP ) {<br><br><br>    // needs templated parameter -- doesn't work<br>    Rcpp::class_< Base >( "Base" )<br>      <br>      // exposing interface specialization member function<br>      .method( "operation", & Base::operation )<br>      <br>    ;<br><br><br>    // exposing the class<br>    Rcpp::class_< Multiply >( "Multiply" )<br>    <br>      // explicit inheritance<br>      // .derives< Base >( "Base" )<br><br>      // exposing the default constructor<br>      .constructor< double, double >( )<br><br>      // exposing Base member functions<br>      // .method( "operation", & Multiply::operation ) // doesn't work <br><br>    ;<br>    <br>    // idem above<br>    Rcpp::class_< Sum >( "Sum" )<br>    <br>      // explicit inheritance<br>      // .derives< Base >( "Base" )<br>    <br>      .constructor< double, double >( )<br>      <br>      .method( "operation", & Sum::implementation ) // works :) but it isn't CRTP<br>      <br>    ;<br>    <br>}<br><div><br>Cheers,<br>FH<br></div></div>