Anonymous function: Difference between revisions

Content deleted Content added
C++ (since C++11): Complete the syntax of lambdas
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 603:
[[C++11]] supports anonymous functions (technically [[function object]]s), called ''lambda expressions'',<ref>{{Cite web|title=Lambda expressions (since C++11) - cppreference.com|url=https://en.cppreference.com/w/cpp/language/lambda|access-date=2022-01-14|website=en.cppreference.com}}</ref> which have the form:
<syntaxhighlight lang="cpp">
[ captures ] ( params ) specs requires (optional) { body }
[capture](parameters) trailing_return_type { function_body }
</syntaxhighlight>
where "<code>trailing_return_typespecs</code>" is optional and is of the form "<code>->specifiers return_typeexception attr trailing-return-type</code> in that order; each of these components is optional". If it is absent, the return type is deduced from <code>return</code> statements as if for a function with declared return type <code>auto</code>.
 
This is an example lambda expression: