Skip to content
Prev 3151 / 10988 Next

[Rcpp-devel] Using lbfgsb with a Rcpp::List.

double fr(int n, double *par, void *ex) {
	double x1 = par[0];
	double x2 = par[1];
//	double blah = Rcpp::as<double>(ex["numbers"]);
...


void* means a pointer to anything. So if you know it is an Rcpp::List*,
you'd do:
   Rcpp::List *p=static_cast<Rcpp::List>(ex);
   double blah = Rcpp::as<double>(*p["numbers"]);

Note the *p to dereference the pointer. This version might also work and
be more readable:
   Rcpp::List &TheList=*(static_cast<Rcpp::List>(ex));
   double blah = Rcpp::as<double>(TheList["numbers"]);

Both of them untested.

As Dirk is saying, using void* is C-style code. C++ style would use
templates and functors to be both safer and slightly quicker.

Darren