Commit c40964c8 authored by Petr Rockai's avatar Petr Rockai
Browse files

bricks: Add local_override, a 'dynamic scope' RAII helper.

parent c68ec595
Loading
Loading
Loading
Loading
+20 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,26 @@ namespace brq
        finally( const finally & ) = delete;
        finally( const finally & ) = delete;
    };
    };


    template< typename val_t >
    struct local_override
    {
        val_t &value;
        val_t backup;

        local_override( val_t &v, val_t local )
            : value( v ), backup( v )
        {
            value = local;
        }

        ~local_override()
        {
            value = backup;
        }

        local_override( const local_override & ) = delete;
    };

    struct terminate_guard
    struct terminate_guard
    {
    {
        int exit_code;
        int exit_code;