C++ lambda expression
程序员文章站
2022-06-05 18:16:25
Emerged since c++11, lambda expression/function is an unnamed function object capable of capturing variables in scope. 1. syntax of a lambda expressio ......
emerged since c++11, lambda expression/function is an unnamed function object capable of capturing variables in scope.
1. syntax of a lambda expression
[
captures ]
<tparams>(optional)(c++20) (
params )
specifiers exception attr ->
ret requires(optional)(c++20){
body }
[
captures ]
(
params )
->
ret {
body }
[
captures ]
(
params )
{
body }
[
captures ]
{
body }
examples:
[](){} //barebone lambda
[](){}() // immediately execute a lambda
auto print = [](const int& n) { n = n+1; std::cout << " " << n; };
std::for_each(v.begin(), v.end(), print); // caller of the lambda expression
std::for_each(v.begin(), v.end(), [](int &n){ n++; });
上一篇: 删除单链表,你会吗?
推荐阅读
-
2020-12-11 C++文件操作
-
c/c++ 重载运算符 ==和!=的重载
-
Node.js C++ 插件学习指南
-
MySQL:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY with sql_mode=only_full_group
-
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains
-
mysql执行sql语句提示Expression #1 of ORDER BY clause is not in GROUP BY
-
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column xxxx
-
求教,QQ和YY那个弹窗结构是用什么语言结构?html?xml?结合的是c c++ 还是?_html/css_WEB-ITnose
-
C++分治策略实现快速排序
-
php常用的排序算法与二分法查找 二分法排序 c++二分法排序 二分法插入排