After reading this question on implementing Go's defer in C++:
I had a question on the performance of the go-defer like guard clause in given in one of the answers. It uses a shared_ptr deleter which ignores the passed object address.
If the deleter ignores the address using an unnamed parameter, will it still be passed on the stack.
Will there be any difference in any of the following ways of accomplishing the defer?
#include <memory>
#include <iostream>
#include <functional>
using namespace std;
using defer = shared_ptr<void>;
int main() {
defer defer0 (nullptr, [](...) { cout << "defer0\n"; }); // this is the version i've seen
// but will the performance be any different using any of these?
shared_ptr<int> defer1(nullptr, [](int* dummy) { cout << "defer1\n"; });
shared_ptr<int> defer2(nullptr, [](int*) { cout << "defer2\n"; });
shared_ptr<void> defer3(nullptr, [](void*) { cout << "defer3\n"; });
unique_ptr<int,void(*)(int*)> defer4(nullptr, [](int*) { cout << "defer4\n"; });
cout << "Hello\n";
}