Skip to content

as_cpp<Enum> #52

@romainfrancois

Description

@romainfrancois

It would be nice to have some mechanism to move enums back and forth between R and C++. I'm not sure what as_sexp() would do but as_cpp<Enum> could be:

namespace cpp11 {

template <typename E>
typename std::enable_if<std::is_enum<E>::value, E>::type as_cpp(SEXP from) {
  return E(cpp11::as_cpp<typename std::underlying_type<E>::type>(from));
}

}

If this is of interest, I'll polish and make it a proper pull request.

In Rcpp we had to use the RCPP_EXPOSED_ENUM_NODECL macro to declare each enum we wished to expose, manually, which sets some templates for Rcpp::as<> and Rcpp::wrap<>. IIRC, Rcpp cannot use the is_enum trait because it's a C++11 thing. https://github.com/RcppCore/Rcpp/blob/f3c5a34e06e774532227470b01c63a8f08ce4313/inst/include/Rcpp/macros/module.h#L76

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions