A static lambda (introduced in C++23) is a lambda expression explicitly declared with theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
static specifier, which instructs the compiler to generate a closure type where the overloaded call operator (operator()) is a static member function rather than a non-static member function.
Because static member functions do not possess an implicit this pointer, a static lambda is strictly prohibited from capturing any state.
Syntax
Thestatic keyword is placed after the parameter list and before any trailing return type, noexcept specifier, requires clause, or the function body.
Compiler Translation
To understand the mechanics, observe how the compiler translates a standard stateless lambda versus a static lambda. Standard Stateless Lambda:operator() itself is static. This eliminates the need for the compiler to generate a separate static __invoke thunk function to facilitate function pointer decay. The call operator natively matches the signature and calling convention of a standard free function.
Constraints and Rules
- Empty Capture List: The capture list must be strictly empty (
[]). Attempting to capture variables by value or reference ([=],[&],[x]) will result in a compilation error, as there is no instantiated closure object state to access. - No
mutableSpecifier: A static lambda cannot be markedmutable. Themutablekeyword is used to remove the implicitconstqualification from a non-staticoperator(), which is semantically invalid for a static member function. - C++ Standard: Requires compilation with
-std=c++23or later.
Invocation Mechanics
Because the call operator is static, the compiler does not need to instantiate or pass a hidden closure object instance (thethis pointer) to invoke the function.
Master C++ with Deep Grasping Methodology!Learn More





