Skip to content

DistroRickDev/defer_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Basic implementation of a defer mechanism in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors