#pragma once
template <typename F>
struct _defer {
	F f;
	_defer(F f) : f(f) {};
	~_defer() { f(); };
};

template <typename F>
_defer<F> MakeDefer(F f) {
	return _defer<F>(f);
}

#define STRING_JOIN(a, b) _STRING_JOIN(a, b)
#define _STRING_JOIN(a, b) a ## b
#define defer(x) auto STRING_JOIN(_defer_, __LINE__) = MakeDefer([=](){x;})