lundi 26 février 2018

declaring templated function as argument to non-templated function

template<typename Type>
void execute(absl::string_view expected_name){
  std::cout << "*** expected type: " << expected_name
            << " | actual type: " << typeid(Type);
}

void handle(std::function<void(absl::string_view)> executor){
  executor<int>("int");
  executor<double>("double");
}

I have this piece of code (which, of course, didn't compile). I want to be able to pass a templated function to a "normal" function and have the "normal" function define the concrete type as it needs, as shown in the example.

Is there a way to declare on the handle parameter list that executor is a templated function?

Aucun commentaire:

Enregistrer un commentaire