[英]Why c++ lambda capture needn't type declaration?
Lambda函数:
auto wc = find_if(words.begin(), words.end(),
[sz](const string &a) //sz does not require type declaration
{
return a.size() >= sz;
})
等于
class SizeComp {
SizeComp(size_t n): sz(n) { } // Type required here.
bool operator()(const string &s) const { return s.size() >= sz; }
private:
size_t sz;
};
为什么lambda捕获sz不需要类型声明?
由于捕获的变量是在父作用域中声明的,因此其类型是已知的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.