Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 822 Bytes

File metadata and controls

39 lines (30 loc) · 822 Bytes

Defer (C++)

Basic implementation of a defer mechanism in C++ inspired by (Go)[https://go.dev/tour/flowcontrol/12]

Build instructions

Example use

void foo_w_arg(int const arg) {
    std::cout << "Print args: " << arg << std::endl;
}

void foo() {
    std::cout << "Hello Foo!" << std::endl;
}

struct TestStruct {
    TestStruct() = default;
    ~TestStruct() {
        std::cout << "Test Destructor" << std::endl;
    }
};

int main() {
    auto * test = new TestStruct();
    defer(delete, test);
    defer(foo);
    defer(foo_w_arg, 42);
    std::cout << "Hello World 1!" << std::endl;
    std::cout << "Hello World 2!" << std::endl;
}

Author

@DistroRickDev

License

License: LGPL v3