惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
月光博客
月光博客
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
U
Unit 42
腾讯CDC
爱范儿
爱范儿
J
Java Code Geeks
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
B
Blog
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - 云山漫卷

AP与网桥概念对比 QT开源社区版账号申请 Lua语法深入1 LUA语法细节 docker 报(docker0)conflicts with network、networks have same bridge name CPU架构的演进(及其背后的指令集的演进) 上下拉电阻 树莓派中可由用户修改的配置文件 Linux下vi常用操作、常用命令 c++ 标准库多线程 git基本操作 Makefile中3个常用自动化变量 添加.pri文件并引入QCustomPlot图表库自定义图表 QTreeWidget 样式表 Qt css颜色对照表 删除界面上控件 设置QT窗体的阴影效果 解决错误no documents matching "ui 错误解决 allocation of incomplete type ‘Ui::
Lambda表达式二例
云山漫卷 · 2025-03-15 · via 博客园 - 云山漫卷

利用mutable生成一个计数器

auto make_counter = [](int start) {
    return [start]() mutable { return start++; };  // mutable允许修改捕获的副本
};
auto counter = make_counter(0);
std::cout << counter();  // 0
std::cout << counter();  // 1

泛型Lambda(C++14+)

支持auto参数,适配多种类型:

auto print = [](const auto& arg) { std::cout << arg; };
print(42);        // 输出int
print("lambda");  // 输出const char*

posted @ 2025-03-15 21:39  云山漫卷  阅读(28)  评论(0)    收藏  举报