Here is a code snippet I have created:
auto f = [](auto a) -> auto {
cout << a << endl;
return a;
};
cout << f(12) << endl;
cout << f("test");
Here is what I know: Types have to be all resolved / specified at compile time.
The question here is, how is the compiler behaving when it sees this lambda function f? How does it deduces all the types for specific use like in line 6 and 7, in which we can see there are two different arguments passed for each call of lambda function f. Is the compiler creating different instances of the lambda function f to match the types passed?
Any help will be appreciated!
Also, if the answer is going to be too technical to be written on a few lines, I'd appreciate for any good reference on lambda functions and how they work.
One thing I have noticed, is that auto is not allowed when defining functions the usual way:
void f(auto a)
{
}
this does not compile.