Basic implementation of a defer mechanism in C++ inspired by (Go)[https://go.dev/tour/flowcontrol/12]
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;
}