1.作为回调函数
using FuncProgressCallback = std::function<bool(int32_t, int32_t)>;
void DLG::SetCallback(int a, const FuncProgressCallback& cb);
void Test()
{
int value;
DLG dlg;
dlg.SetCallback(10, [&value](int pos, int total){
int t = value;
SetProgress(pos, total);
});
}
2.完成函数返回时自动释放工作
void Test()
{
....
int* pValue = new int[100];
std::shared_ptr<void> spCleanUp(NULL, [&pValue](void*) {
if (pValue != NULL)
{
delete[] pValue;
}
});
// dosth
}