A lambda function:
auto wc = find_if(words.begin(), words.end(),
[sz](const string &a) //sz does not require type declaration
{
return a.size() >= sz;
})
is equal to
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;
};
Why does the lambda capture of sz not require a type declaration?
由于捕获的变量是在父作用域中声明的,因此其类型是已知的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.