mercredi 21 août 2019

Implementing a C++ convert on invoke function

I would like to implement a specialized invoke with extra conversion on the arguments using C++11/14. Basically, the idea is:

struct Foo {
  private:
    void* ptr;
  public:
    void* get();
};


template <typename F, typename... Args>
auto convert_invoke(F&& f, Args&&... args) {
  // not sure how to do here with C++11/14
}

// caller side
int simple(float* f1, size_t N) {
  // doing something interesting
}

// ideally I would like to call the following:
Foo foo;
size_t n = 10;

convert_invoke(simple, foo, n); // internally calls simple((float*)foo.get(), n);

The idea here is when the argument is of type Foo, I will do some specialized processing like getting the void* pointer and cast it to the corresponding argument type defined in simple. How can I implement this in convert_invoke?

Aucun commentaire:

Enregistrer un commentaire