C++11 adds the lambda (anonymous) function, which in practice finds it necessary to name anonymous functions (enhanced code readability).
This article describes an elegant way to implement the naming of anonymous functions.
I've found that any way to enhance code readability without violating compiler rules is to define an empty definition, such as:
/** * Macros within the MFC framework that identify message handlers have no practical meaning, but can be seen at a glance as a message processing function. */#ifndef afx_msg #define AFX_MSG//Intentional placeholder #endif
/**
* In and out macros are used to identify the direction in which a function parameter is passed in, some languages (C #)
* directly supports in and out keywords for enhanced readability.
*/
#ifndef in
#define In
#endif
#ifndef out
#define Out
#endif
Along this line of thought it is easy to derive a method named for anonymous functions, defining a meaningful empty macro, as follows:
/**
* Define the name of the anonymous function
*/
#define $ (NAME)
This symbol is selected because it is concise enough to not exclude the effects of some JavaScript frameworks. Your anonymous function can then be used in this way.
if ([&]$ (Testifdigitalzoom) ()->bool{
if (type = = Recalcrect_fitfull | | type = = recalcrect_fitbest)
{
return true;
}
if (Izoomzt > | | izoomzt < 0)
{
return false;
}
/* Scaled after change, whether the machine is scaled */
if (Fzoom * rectcalcor::_zoomkey <= 1.0f && fzoom >= imgsize.width * 1.0f/capsize.width * rectcalcor::_zoo Mkey)
{
return true;
}
Else
{
return false;
}
}())
{
}
What, isn't it cool?
How do I name a lambda (anonymous) function?