This does not work because custom conversions are not taken into account when the template argument is output.
You can either help the compiler by explicitly providing the template arguments, and call simult as:
int r = simult<std::string, int>(fn, args);
Live demo
Or you can do it with decltype like this:
std::string fn(int i) { return std::to_string(i + 1); } template<typename T, typename U> int simult_impl(std::function<T(U)> f, std::vector<U> const &args) { return 666; } template<typename F, typename U> int simult(F f, std::vector<U> const &args) { return simult_impl<decltype(f(args[0])), U>(f, args); }
Live demo
Edit:
If you want to return std::vector<T> provided that your compiler supports C ++ 14, you can change it as follows:
template<typename T, typename U> std::vector<T> simult_impl(std::function<T(U)> f, std::vector<U> const &args) { return std::vector<T>(10, T{"666"}); } template<typename F, typename U> auto simult(F f, std::vector<U> const &args) { return simult_impl<decltype(f(args[0])), U>(f, args); }
Live demo
source share