The following code tries to create a templated lambda and pass it to a function that calls it. However compilation fails because the type of lambda
argument is wrong.
#include <functional>
void foo(std::function<void(void)>&lambda) {
lambda.template operator()<int>();
}
int main() {
auto f = []<class T>() {};
foo(f);
}
How should I define the type of an argument that receives a templated lambda?
Using auto
works but I need the explicit type (so I can modify foo
to return whatever the lambda returns).
void foo(auto &lambda) { // Works but not what I want
I tried this but doesn’t compile:
template<class T>
void foo(std::function<void<T>(void)>&lambda) {