wzit / cpp-defer

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)


Languages

Language:C++ 59.5%Language:Ruby 40.5%