在定义lambda时,如果没有参数,那么C++23可以省略()
#include <string>
#include <iostream>
using namespace std;
int main()
{
auto s = "hello";
auto p = [&]
{
cout<<s<<endl;
};
p();
return 0;
}
运行程序输出:
hello
可以看到C++23中进一步的优化了lambda,使其更加便于使用