Avoid Else, Return Early (2013)
This also works well with a C++ `defer` helper.<p><pre><code>    #define CONCAT_LITERAL(x, y) x ## y
    #define CONCAT(x, y) CONCAT_LITERAL(x, y)

    template &lt;typename F&gt;
        struct DeferWrapper {
            F f;
            DeferWrapper(F f) : f(f) {}
            ~DeferWrapper() { f(); }
        };

    template &lt;typename F&gt;
        DeferWrapper&lt;F&gt; deferWrapper(F f) {
            return DeferWrapper&lt;F&gt;(f);
        }

    #define defer(code) auto CONCAT(_defer_, __COUNTER__) = deferWrapper([&amp;]() code)
</code></pre>
Example of usage:<p><pre><code>    {
        Foo *foo;
        if (initializeFoo()) {
            warn(&quot;Foo could not be initialized&quot;);
            return;
        }
        defer({
            destroyFoo(foo);
        });

        Bar *bar;
        if (initializeBar()) {
            warn(&quot;Bar could not be initialized&quot;);
            return;
        }
        defer({
            destroyBar(bar);
        });
    }
</code></pre>
This way, all initialization and destruction happens in one block of the code on the same level of indentation as everything else. Useful for socket code, file handling, encoding&#x2F;decoding states, etc.