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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -