<div dir="ltr">Hi, <div><br></div><div>I have an enum defined in a C++ library that I would like to export to R. I saw some references to enums in pkg/Rcpp/inst/include/Rcpp/module/Module.h but I could not find any examples of enums being used. Through trial and error I figured out that I could create a dummy class and add the enum to that (see code below). Can I export the enum directly? I saw references to RCPP_EXPOSED_ENUM but I could not figure out how to use that macro. Any help or pointers to examples where enums are used would be appreciated. </div>
<div style><br></div><div style>Regards,</div><div style>Sameer<br></div><div><br></div><div><div>#include "Rcpp.h"</div><div><br></div><div>using namespace Rcpp;</div><div><br></div><div>class Dummy {</div><div>
int x;</div><div> int get_x() {return x;}</div><div>};</div><div><br></div><div>enum MyEnum {ENUM0, ENUM1, ENUM2};</div><div><br></div><div><br></div><div>RCPP_MODULE(EnumMod) {</div><div> class_<Dummy>("EnumMod")</div>
<div> .default_constructor()</div><div> ;</div><div><br></div><div> enum_<MyEnum, Dummy>("EnumType")</div><div> .value("Enum0", ENUM0)</div><div> .value("Enum1", ENUM1)</div>
<div> .value("Enum2", ENUM2)</div><div> ;</div><div>}</div></div><div><br></div></div>