#include <iostream>
#include <sstream>
using namespace std;
class ScopeGuard
{
bool commited;
stringstream accumulator;
public:
ScopeGuard() : commited(false) {}
void commit()
{
commited = true;
}
bool done() const
{
return commited;
}
template<typename Data>
ScopeGuard &operator<<(const Data &x)
{
accumulator << x;
return *this;
}
~ScopeGuard()
{
if(commited)
cout << accumulator.str();
}
};
#define LOG(anything) \
for(ScopeGuard guard; !guard.done(); guard.commit()) \
guard \
/**/
int main()
{
try
{
LOG(lg) << "Failure" << (false ? "\n" : throw 1);
}
catch(...) {}
LOG(lg) << "Success" << (true ? "\n" : throw 1);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBTY29wZUd1YXJkCnsKICAgIGJvb2wgY29tbWl0ZWQ7CiAgICBzdHJpbmdzdHJlYW0gYWNjdW11bGF0b3I7CnB1YmxpYzoKICAgIFNjb3BlR3VhcmQoKSA6IGNvbW1pdGVkKGZhbHNlKSB7fQogICAgdm9pZCBjb21taXQoKQogICAgewogICAgICAgIGNvbW1pdGVkID0gdHJ1ZTsKICAgIH0KICAgIGJvb2wgZG9uZSgpIGNvbnN0CiAgICB7CiAgICAgICAgcmV0dXJuIGNvbW1pdGVkOwogICAgfQogICAgdGVtcGxhdGU8dHlwZW5hbWUgRGF0YT4KICAgIFNjb3BlR3VhcmQgJm9wZXJhdG9yPDwoY29uc3QgRGF0YSAmeCkKICAgIHsKICAgICAgICBhY2N1bXVsYXRvciA8PCB4OwogICAgICAgIHJldHVybiAqdGhpczsKICAgIH0KICAgIH5TY29wZUd1YXJkKCkKICAgIHsKICAgICAgICBpZihjb21taXRlZCkKICAgICAgICAgICAgY291dCA8PCBhY2N1bXVsYXRvci5zdHIoKTsKICAgIH0KfTsKCiNkZWZpbmUgTE9HKGFueXRoaW5nKSBcCmZvcihTY29wZUd1YXJkIGd1YXJkOyAhZ3VhcmQuZG9uZSgpOyBndWFyZC5jb21taXQoKSkgXAogICAgZ3VhcmQgXAovKiovCiAKCmludCBtYWluKCkKewogICAgdHJ5CiAgICB7CiAgICAgICAgTE9HKGxnKSA8PCAiRmFpbHVyZSIgPDwgKGZhbHNlID8gIlxuIiA6IHRocm93IDEpOwogICAgfQogICAgY2F0Y2goLi4uKSB7fQoKICAgIExPRyhsZykgPDwgIlN1Y2Nlc3MiIDw8ICh0cnVlID8gIlxuIiA6IHRocm93IDEpOwp9