Coder Social home page Coder Social logo

kuhf / scopeguard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from butyllee/scopeguard

0.0 0.0 0.0 91 KB

A header-only, modern C++ and fast facility ScopeGuard that provide multiple usages which are simple and easy to use.

Home Page: http://origought.cn/2021/cpp/88/

License: Apache License 2.0

C++ 100.00%

scopeguard's Introduction

ScopeGuard

A header-only, modern C++ and fast facility ScopeGuard that provide multiple usages which are simple and easy to use as other languages provide.

C++14 or later standard is required.

Simple examples

There're 3 ways to use ScopeGuard:

  1. Put the code executing when leaving current scope in code block finally{ }.
#include "ScopeGuard.h"
...
{
    ...
    finally{
        // callback statments
        // such as releasing resources
    };
    ...
} // callback statments are executed at this point
  1. put callable in INVOKE_ON_EXIT( )
...
{
    void my_callback();
    ...
    INVOKE_ON_EXIT(my_callback);
    ...
    INVOKE_ON_EXIT([&] { /* releasing resources */ });
    ...
} // lambda and my_callback are invoked at this point
  1. using the make function MakeScopeGuard manually.
...
{
    ...
    auto guard = sg::MakeScopeGuard(my_callback);
    ...
} // my_callback is invoked at this point

You could see the comments in ScopeGuard.h for more.

Tutorial

See tutorial here and also here (Chinese).

scopeguard's People

Contributors

butyllee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.