自己寫的scope exit
感覺比boost的好用

class Scope_Exit
{
    std::function<void()> func;
    public:
    Scope_Exit(std::function<void()> f): func(f) { }
    ~Scope_Exit() { func(); }
};

#define CONCAT_I(a, b) a##b
#define CONCAT(a, b) CONCAT_I(a, b)
#define SCOPE_EXIT(var) Scope_Exit CONCAT(af_, __COUNTER__) ([&](){var;})

用法

    int a = 0;
    {
        SCOPE_EXIT(a = 5);
        a = 6;
    }
    assert(a == 5);