Comment

Comment by toth

That is a pretty cool use. In practice though, it is pretty unreadable unless you wrap it in a macro or template, and if you are doing that you might as well just implement it yourself. Something like:

    struct OnScopeExit {
        OnScopeExit(std::function<void()> f) :  f_(f) {};
        ~OnScopeExit() { f_();};
        std::function<void()> f_;
    };
Which you'd then use as

    {
        OnScopeExit x([]() { std::cout << "Exited scope!" << std:endl; };
        // ...
    }
parent toth 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton