利用已有的bind构造ScopeExit (三)

2014-11-24 12:03:42 · 作者: · 浏览: 4
= strData.GetLength() * sizeof(TCHAR);
DWORD dwWritten = 0;

if (!WriteFile(hFile, (LPCTSTR)strData, dwToWrite, &dwWritten, NULL) || dwWritten != dwToWrite)
{
return false;
}

// if (...)
// {
// return false;
// }
//
// ...
//

sgDeleteFile.Dismiss();

return true;
}

高亮部分,就是比 Loki 使用起来麻烦的地方。如果明确了是使用 boost::bind 或 xl::Bind,那就写成:
ScopeGuard sgDeleteFile = MakeGuard(boost::bind(DeleteFile, FILE_NAME));

ScopeGuard sgDeleteFile = MakeGuard(xl::Bind(DeleteFile, FILE_NAME));
(有个区别是,如果绑定成员函数,boost::bind 的对象指针在第二个参数,xl::Bind 在第一个参数。)

好了,写到这里。请各位指教。
至此,xlLib 里面玩语法的部分也就差不多了。接下来将会注重功能性的东西。


摘自 溪流漫话