Question about implicit lambda conversions. I have this type:
class A {
public:
A(std::function<void(std::string)> func) {
....
}
};
Which I believe has a valid copy constructor.
As I would like to do the following
A a = [](std::string param) { ... };
Or
void MyFunc(A a) { ... } // definition
MyFunc([](std::string param) { ... }); // call
Yet both these yield compile error:
note: candidate constructor not viable: no known conversion from '(lambda at ....)' to 'std::function' for 1st argument
Why is this? Or should this be possible?
lambda
s (emphasis added): "Instances ofstd::function
can store, copy, and invoke any Callable target -- functions, lambda expressions, bind expressions, or other function objects, as well as pointers to member functions and pointers to data members." It includes an example which stores such alambda
directly, so it should work just fine. – ShadowRanger