template struct Defer_Guard { Defer_Guard(F && f) : _f(f) {} ~Defer_Guard() { _f(); } F _f; }; struct Defer_Guard_Helper { template Defer_Guard operator+(F&& f) { return Defer_Guard(std::forward(f)); } }; #define CONCAT_STR_INTERNAL(A, B) A##B #define CONCAT_STR(A, B) CONCAT_STR_INTERNAL(A, B) #define defer const auto CONCAT_STR(defer_, __LINE__) = Defer_Guard_Helper{} + [&]