The Secret Life of C++: Anonymous Functions and Captures

A big addition to C++11 was standardized support for anonymous functions and closures.

Basic Anonymous Function


        

        

        

        

        
__ZNSt3__18functionIFiiiEEC1IZ12anonFunctionvE3$_0EET_PNS_9enable_ifIXaasr10__callableIS5_EE5valuentsr7is_sameIS5_S2_EE5valueEvE4typeE is std::__1::function<int (int, int)>::function<anonFunction()::$_0>(anonFunction()::$_0, std::__1::enable_if<(__callable<anonFunction()::$_0>::value) && (!(is_same<anonFunction()::$_0, std::__1::function<int (int, int)> >::value)), void>::type*)

__ZNSt3__18functionIFiiiEED1Ev is std::__1::function<int (int, int)>::~function()

__ZNKSt3__18functionIFiiiEEclEii is std::__1::function<int (int, int)>::operator()(int, int) const

Anonymous Function with Capture


        

        

        

        

        

Capture by Reference on the Stack


        

        

        

        

        

Calling with Reference on the Stack after return


        

        

        

        

        
Fork me on GitHub