'Calling a purely template lambda callback in C++20 [duplicate]
With C++20, we've gained templated lambdas, great!
[]<class T>(){};
Is it possible to call a lambda callback with a template parameter, but no argument to deduce it from?
For ex,
template <class Func>
void do_it(Func&& func) {
// Call lambda with template here, but don't provide extra arguments.
// func<int>(); ?
}
do_it([]<class T>(){ /* do something with T */ });
Solution 1:[1]
Is it possible to call a lambda callback with a template parameter, but no argument to deduce it from?
This is probably what you want
template <class Func>
void do_it(Func&& func) {
func.template operator()<int>();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 康桓瑋 |
