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:<p><pre><code>    struct OnScopeExit {
        OnScopeExit(std::function&lt;void()&gt; f) :  f_(f) {};
        ~OnScopeExit() { f_();};
        std::function&lt;void()&gt; f_;
    };
</code></pre>
Which you&#x27;d then use as<p><pre><code>    {
        OnScopeExit x([]() { std::cout &lt;&lt; &quot;Exited scope!&quot; &lt;&lt; std:endl; };
        &#x2F;&#x2F; ...
    }</code></pre>