Skip to content

later() c++ interface should accept something like boost::function0<void> #26

@wch

Description

@wch

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();
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions