#include <iostream>
#include <stdexcept>
#include <iomanip>
using namespace std;
struct vantuz
{
vantuz& push();
vantuz& pull();
vantuz();
private:
bool pushed;
};
vantuz::vantuz():pushed(false)
{
}
vantuz& vantuz::push()
{
if(pushed)
{
throw logic_error("already pushed!");
}
pushed=!pushed;
cout<<"push! ";
return *this;
}
vantuz& vantuz::pull()
{
pushed=!pushed;
if(pushed)
{
throw logic_error("already pulled!");
}
cout<<"pull! ";
return *this;
}
int main()
{
try
{
vantuz v;
v.push().pull().push().pull().push().pull().push().pull();
}
catch(logic_error& ex)
{
cout<<endl<<setw(20)<<setfill('@')<<' '<<"Runtime error!"<<setw(20)<<setfill('@')<<' '<<endl<<ex.what()<<endl;
throw;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkZXhjZXB0PgojaW5jbHVkZSA8aW9tYW5pcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgpzdHJ1Y3QgdmFudHV6CnsKICAgdmFudHV6JiBwdXNoKCk7CiAgIHZhbnR1eiYgcHVsbCgpOwogICB2YW50dXooKTsKcHJpdmF0ZToKICAgYm9vbCBwdXNoZWQ7Cn07Cgp2YW50dXo6OnZhbnR1eigpOnB1c2hlZChmYWxzZSkKewp9Cgp2YW50dXomIHZhbnR1ejo6cHVzaCgpCnsKICAgICAgICBpZihwdXNoZWQpCiAgICAgICAgewogICAgICAgICAgICAgIHRocm93IGxvZ2ljX2Vycm9yKCJhbHJlYWR5IHB1c2hlZCEiKTsKICAgICAgICB9CiAgICAgICAgcHVzaGVkPSFwdXNoZWQ7CgkJY291dDw8InB1c2ghICI7CiAgICAgICAgcmV0dXJuICp0aGlzOwp9Cgp2YW50dXomIHZhbnR1ejo6cHVsbCgpCnsKICAgIHB1c2hlZD0hcHVzaGVkOwogICAgaWYocHVzaGVkKQogICAgewogICAgICAgICAgdGhyb3cgbG9naWNfZXJyb3IoImFscmVhZHkgcHVsbGVkISIpOwogICAgfQogICBjb3V0PDw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