Given this code:
#include <iostream>
#include <functional>
template<typename T>
void f(T t1, T t2) { std::cout << t1 << " " << t2 << std::endl; }
template<typename...Ts>
void g(Ts... ts) { f(ts...); }
int main() {
auto f = std::bind(g<int, int>, 1, 2);
f();
return 0;
}
Is there any way to skip the template type specification for g
in std::bind(g<int, int>, 1, 2)
?
If not, is it at least possible to specify the type just once? ie std::bind(g<int>, 1, 2)
Here is a live version of this.
I'm not sure if it's possible with bind, but you get same functionality with a lambda, and no need for explicit template params:
auto f = []{
g(1, 2);
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.