lamba表达式 c++

来源:互联网 发布:淘宝上好的女鞋外贸店 编辑:程序博客网 时间:2024/06/01 09:47

  

语法:


[capture](parameters) mutable ->return-type{statement}


捕获参数 , 参数列表 ,参数是否可变 ,返回值,函数体


例如 add 函数:


auto addFunc = [](int x, int y) mutable throw() ->int { return x + y; };

std::cout<< addFunc(10, 20);


例如vector 遍历:


std::vector<int> vec{ 123, 234};

std::for_each(vec.begin(), vec.end(), [](int& value){std::cout << value << std::endl; });


0 0
原创粉丝点击