#include <iostream>
#include <functional>
using namespace std;
class DoInDtor
{
public:
typedef function<void()> F;
DoInDtor(F f) : f_(f) {};
~DoInDtor() { f_(); }
private:
F f_;
};
void foo()
{
for(;;)
{
DoInDtor byeSayerCustom([](){ cout << "bye\n"; });
auto cond = true; // could of course also be false sometimes
if (cond)
break;
}
// ...
return;
}
int main()
{
foo();
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICNpbmNsdWRlIDxmdW5jdGlvbmFsPgoKICAgIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CgogICAgY2xhc3MgRG9JbkR0b3IKICAgIHsKICAgIHB1YmxpYzoKICAgICAgICB0eXBlZGVmIGZ1bmN0aW9uPHZvaWQoKT4gRjsKICAgICAgICBEb0luRHRvcihGIGYpIDogZl8oZikge307CiAgICAgICAgfkRvSW5EdG9yKCkgeyBmXygpOyB9CiAgICBwcml2YXRlOgogICAgICAgIEYgZl87CiAgICB9OwoKICAgIHZvaWQgZm9vKCkKICAgIHsKICAgICAgICBmb3IoOzspCiAgICAgICAgewogICAgICAgICAgICBEb0luRHRvciBieWVTYXllckN1c3RvbShbXSgpeyBjb3V0IDw8ICJieWVcbiI7IH0pOwogICAgICAgICAgICBhdXRvIGNvbmQgPSB0cnVlOyAvLyBjb3VsZCBvZiBjb3Vyc2UgYWxzbyBiZSBmYWxzZSBzb21ldGltZXMKICAgICAgICAgICAgaWYgKGNvbmQpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgLy8gLi4uCiAgICAgICAgcmV0dXJuOwogICAgfQoKICAgIGludCBtYWluKCkKICAgIHsKICAgICAgICBmb28oKTsKICAgIH0=