#include <iostream>
int main(){
auto lambda = [] {
return 7;
};
std::cout << lambda() << '\n';
}
This program compiles and prints 7.
The return type of the lambda is deduced to the integer type based on the return value of 7.
Why isn't this possible with ordinary functions?
#include <iostream>
auto function(){
return 42;
}
int main(){
std::cout << function() << '\n';
}
error: ‘function’ function uses ‘auto’ type specifier without trailing return type