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

推荐订阅源

罗磊的独立博客
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
U
Unit 42
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
腾讯CDC
I
InfoQ
GbyAI
GbyAI
博客园_首页

博客园 - 云山漫卷

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)    收藏  举报