My book says this:
Lambdas with function bodies that contain anything other than a single return statement that do not specify a return type return vo
If you use popular compilers (gcc, Visual Studio), you usually don't need to specify return type as long as the compiler is able to determine it unambiguously - like in your example.
The following example shows a lambda, which requires explicit return type information:
auto lambda = [](bool b) -> float
{
if (b)
return 5.0f;
else
return 6.0;
};
I asked Bjarne Stroustrup regarding this matter, his comment:
I do not know if C++11 allows the deduction of the return type is there are several return statements with identical return type. If not, that's planned for C++14.