The Callback class stores a boost::function0<void> object, but it can be passed a Rcpp::Function object, as is done here:
https://github.com/r-lib/later/blob/c1c3b09/src/callback_registry.cpp#L9
This suggests that it might be possible to allow users to pass in some sort of generic function-like object, without requiring them to use boost.
If that doesn't work, we could supply a pure virtual class that others could implement. For example, on a branch of httpuv, there's a Callback class:
class Callback {
public:
virtual ~Callback() {};
virtual void operator()() = 0;
};
And here is an implementation that takes boost::function objects:
#include <boost/function.hpp>
// Wrapper class for boost functions
class BoostFunctionCallback : public Callback {
private:
boost::function<void (void)> fun;
public:
BoostFunctionCallback(boost::function<void (void)> fun)
: fun(fun) {
}
void operator()() {
fun();
}
};
The
Callbackclass stores aboost::function0<void>object, but it can be passed aRcpp::Functionobject, as is done here:https://github.com/r-lib/later/blob/c1c3b09/src/callback_registry.cpp#L9
This suggests that it might be possible to allow users to pass in some sort of generic function-like object, without requiring them to use boost.
If that doesn't work, we could supply a pure virtual class that others could implement. For example, on a branch of httpuv, there's a
Callbackclass:And here is an implementation that takes
boost::functionobjects: