C++: why this simple Scope Guard works?
问题 Every looked at scope guard so far has a guard boolean variable. For example, see this discussion: The simplest and neatest c++11 ScopeGuard But a simple guard works (gcc 4.9, clang 3.6.0): template <class C> struct finally_t : public C { finally_t(C&& c): C(c) {} ~finally_t() { (*this)(); } }; template <class C> static finally_t<C> finally_create(C&& c) { return std::forward<C>(c); } #define FINCAT_(a, b) a ## b #define FINCAT(a, b) FINCAT_(a, b) #define FINALLY(...) auto FINCAT(FINALY_, _