vendredi 5 janvier 2018

Get the type of std::bind in compile time

How can I get the type of a std::bind expression to store it in a class member? For example, I have this:

template<class F, class ...Args>
void foo(F&& funct, Args&&... args) {
  typedef decltype(std::bind(funct, std::forward<Args>(args)...)) T;
  T bar = std::bind(funct, std::forward<Args>(args)...);
}

But I want to convert it into:

template<class F, class ...Args>
class Foo {
  void foo(F&& funct, Args&&... args) {
    bar = std::bind(funct, std::forward<Args>(args)...);
  }
  T bar;  // what is the type of bar?
}

Aucun commentaire:

Enregistrer un commentaire