mardi 7 mai 2019

Deduce std::function parameters from actual function

Given a class

class Foo {
 public:
  std::shared_ptr<const Bar> quux(const std::string&, std::uint32_t);
}

I can declare an std::function that has the same interface:

std::function<std::shared_ptr<const Bar>(const std::string&, std::uint32_t)> baz = ...

Is there a way of compressing that declaration such that the template arguments to std::function are derived from the declaration of that method, something like:

std::function<functype(X::quux)> baz = ...

where functype is an imaginary C++ operator similar to decltype. Is there a way to do this / does C++ have such a capability?

I do see that the method has a slightly different signature actually as it would also take a reference/pointer to the this object; it would be fine for me to derive such a signature too.

Aucun commentaire:

Enregistrer un commentaire