Skip to content
/ cpp-defer Public

defer action to end of scope (C++11 only / header-only)

Notifications You must be signed in to change notification settings

xdbr/cpp-defer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-defer

defer action to end of scope (C++11 only / header-only)

Description

Header-only library to defer actions to end of scope (with test)

Examples

#include "defer.hpp"

#include <cassert>
#include <fstream>

auto main() -> int { // C++11 only.

    std::ofstream out("testfile", std::ios::out);

    {
        util::defer( [&]{ out.close(); });
    }

    assert(!out.is_open());
}

Usage

  • include the header file
  • Compile your executable/library with -std=c++11
    • (for now, this is a C++11-only header, and availability of C++11 is not checked)

License

WTFPL

About

defer action to end of scope (C++11 only / header-only)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published