Skip to content

YuuFrag学习记录 共享笔记库

与你的相遇就是奇迹

RECENT_UPDATES 最近更新

2026.06.23

Benchmark 场景数据和 Seed

2026.06.22

Benchmark

2026.06.22

前缀和哈希

2026.06.22

字符串前缀和哈希

2026.06.22

Shader Interface Stable Hash

2026.06.21

Lambda

Lambda

快速的封装一个函数对象 —— 注意,是一个匿名类对象

对象

C++
auto add = [](int a, int b)
{
	return a + b;
};

int x = add(1, 2);

最简单的写法,实际上在语义上等价于 ——

C++
struct SomeGeneratedCallable
{
    int operator()(int a, int b) const
    {
        return a + b;
    }
};

auto add = SomeGeneratedCallable{};
int x = add(1, 2);

因为它实际上是对象,所以才会有后面生命周期,各种妙妙捕获等的问题出现(

基础语法

(蛮看看,其实感觉没什么用

由于常说它是匿名函数,所以参数列表和函数体是必然有的,其返回值可以自动推断所以问题不大。

C++
[capture](parameters) -> return_type
{
    body
};

| 部分 | 意义 | |

Released under the MIT License.