#include <iostream>
#include <memory>
using namespace std;
struct Foo
{
Foo() { cout << "*"; }
~Foo() { cout << "@"; }
Foo(const Foo&) { cout << "="; }
};
int main() {
// your code goes here
cout << "construct:";
Foo *foo = new Foo[5];
cout << endl;
int *p = new int;
cout << "int: " << *p << endl;
delete p;
int *n = new int[5];
for (int i = 0; i < 5; i++)
cout << n[i] << " ";
cout << endl;
delete [] n;
cout << "destruct:";
delete [] foo;
cout << endl;
cout << "************" << endl;
allocator<Foo> allo;
Foo *a;
Foo b;
cout << endl << "+++" << endl;
a = allo.allocate(5);
//new ((void*)(a+2)) Foo(b);
allo.construct(a, b); cout << endl;
cout << "fo" << endl;
allo.destroy(a);
allo.deallocate(a, 0); cout << endl;
cout << "************" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEZvbwp7CglGb28oKSB7IGNvdXQgPDwgIioiOyB9Cgl+Rm9vKCkgeyBjb3V0IDw8ICJAIjsgfQoJRm9vKGNvbnN0IEZvbyYpIHsgY291dCA8PCAiPSI7IH0KCQp9OwoKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCgkKCWNvdXQgPDwgImNvbnN0cnVjdDoiOwoJRm9vICpmb28gPSBuZXcgRm9vWzVdOwoJY291dCA8PCBlbmRsOwoJCglpbnQgKnAgPSBuZXcgaW50OwoJY291dCA8PCAiaW50OiAiIDw8ICpwIDw8IGVuZGw7CglkZWxldGUgcDsKCQoJaW50ICpuID0gbmV3IGludFs1XTsKCWZvciAoaW50IGkgPSAwOyBpIDwgNTsgaSsrKQoJCWNvdXQgPDwgbltpXSA8PCAiICI7Cgljb3V0IDw8IGVuZGw7CglkZWxldGUgW10gbjsKCQoJY291dCA8PCAiZGVzdHJ1Y3Q6IjsKCWRlbGV0ZSBbXSBmb287Cgljb3V0IDw8IGVuZGw7CgkKCQoJY291dCA8PC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