c++ - explain this code with decltype in it -
([] () -> decltype(std::cout << "hello") { return std::cout << "hello"; }()) << ", world!";
prints hello, world!
.
i don't understand what's going on here. can explain me in simple terms?
([] () -> decltype(std::cout << "hello")
this creates lambda (in-place function) same return type expression std::cout << "hello"
has - that's std::ostream&
. []
starts lambda, ()
empty parameter list, ->
preceeds return type, , decltype(x)
equivalent type of expression x. function body:
{ return std::cout << "hello"; }
then function called... outputs "hello" , returns stream....
())
and finally, returned stream, little more text sent...
<< ", world!";
Comments
Post a Comment