template <typename F>
struct Defer_Guard {
  Defer_Guard(F && f) : _f(f) {}
  ~Defer_Guard() { _f(); }
  F _f;
};
struct Defer_Guard_Helper {
  template <typename F>
  Defer_Guard<F> operator+(F&& f) { return Defer_Guard<F>(static_cast<F &&>(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{} + [&]