Code | Term | Description |
---|---|---|
Lambda | ||
Capture | Access to state from where the lambda is defined. We will leave it empty for now as this is a whole topic, and only an empty capture can be used with function pointer parameters. | |
Parameters | Pass state from the code that calls the lambda function | |
Return type | Can be any function return type. Optional if void . In many cases, the compiler can derive the return type. |
|
Body | Definition of the lambda function. Where the statements go. Anything you can do in a free function you can do in a lambda function |
lambda | Description |
---|---|
IN parameter | |
IN/OUT parameter |
bool
comparisionint
comparisionAspect | Function Pointer | Lambda Function |
---|---|---|
Definition | The function must be defined before it can be passed to a pointer | Defined inline where it's used, with its body enclosed in {} and parameters in () |
Scope | Global or namespace scope for the function being pointed to | Scope is limited to where the lambda is defined |
Capturing External Variables | Not directly possible. External variables must be passed as parameters | Can capture external variables from the surrounding scope either by value or by reference [&] |
Portability | Highly portable and compatible with C interfaces | C++11 |
Performance | Slightly slower than a direct call | Provides more potential for compiler optimization |
[]
) and captured variables are very important