#include <iostream>
#include <memory>
using namespace std;
template <class T>
inline void out(const T& t) { cout << t << endl; }
inline void out(const char* str) { cout << str << endl; }
template <class T>
inline void out(const char* str, const T& t)
{ cout << str << ' ' << t << endl; }
class Obj
{
private:
static int count;
int num;
public:
Obj() : num(count++) { out("new", num); }
~Obj() { out("delete", num); }
void o() { out("mynum", num); }
};
int Obj::count = 0;
auto_ptr<Obj> foo() {
out("in foo");
auto_ptr<Obj> tmp(new Obj);
out("out foo");
return tmp;
}
int main() {
out("start");
auto_ptr<Obj> o(new Obj);
auto_ptr<Obj> e(new Obj);
auto_ptr<Obj> p(new Obj);
out("call foo");
o = foo();
e = o;
p = move(o);
out("back to main");
out(o.get());
out(e.get());
out(p.get());
out("finish");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGUgPGNsYXNzIFQ+CmlubGluZSB2b2lkIG91dChjb25zdCBUJiB0KSB7IGNvdXQgPDwgdCA8PCBlbmRsOyB9CmlubGluZSB2b2lkIG91dChjb25zdCBjaGFyKiBzdHIpIHsgY291dCA8PCBzdHIgPDwgZW5kbDsgfQp0ZW1wbGF0ZSA8Y2xhc3MgVD4KaW5saW5lIHZvaWQgb3V0KGNvbnN0IGNoYXIqIHN0ciwgY29uc3QgVCYgdCkKCXsgY291dCA8PCBzdHIgPDwgJyAnIDw8ICB0IDw8IGVuZGw7IH0KCmNsYXNzIE9iagp7CnByaXZhdGU6CglzdGF0aWMgaW50IGNvdW50OwoJaW50IG51bTsKcHVibGljOgoJT2JqKCkgOiBudW0oY291bnQrKykgeyBvdXQoIm5ldyIsIG51bSk7IH0KCX5PYmooKSB7IG91dCgiZGVsZXRlIiwgbnVtKTsgfQoJdm9pZCBvKCkgeyBvdXQoIm15bnVtIiwgbnVtKTsgfQp9OwppbnQgT2JqOjpjb3VudCA9IDA7CgphdXRvX3B0cjxPYmo+IGZvbygpIHs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