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 void.
but this:
auto f = []{
int i=0; i++;
return std::string("foo");
};
std::cout << f() << std::endl;
actually compiles and prints out "foo", but that lambda expr has more than just a single return statement so it should return void, because it does not manually specify "-> std::string" as a return type.
What's going on here?
I'm using Apple's compiler in the latest Xcode 4.6, based on Clang 3.2 it seems:
clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…