Lamda表达式使用[&],可以访问外部的变量。
实例如下:
uh::scope_guard scopeGuardGetInfo([&]() {
std::vector<long> vecInt{};
for(long index = 0L; index <= ; ++index)
{
vecInt.emplace_back(index);
auto itr = m_mapInfo.find(index);
if( itr != m_mapInfo.end() )
m_mapInfo.erase(itr);
}
});
其中:
m_mapInfo是该【Lamda表达式】定义外的变量。