deferxx C++11中Go的类似defer的语法范围守卫习惯用法
用法defer ( ); defer ( ) namely ( );例子if ((fd = mkstemp(buf)) < 0) return -1; defer(close(fd); unlink(buf)); // auto-close, auto-delete when scope exits. defer(vec_.pop_back()) namely(undoer); vec_.push_back(x); /* something may fail */ undoer.dismiss(); // strong guarantee也可以看看[1] C++11(及现代C++)和快速迭代式开发[2]通用:改变你编写异常安全代码的方式
用户评论