It seems that allocator does the same work as “placement new” and “operator new”. and its interface is more convenient.

For example:

string *ps = static_cast<string *>(operator new(sizeof(string)));
new (ps) string("Hello");
cout<<*ps<<endl;

can be rewritten to

allocator<string> as;
string *ps2 = as.allocate(1);
as.construct(ps2,"Hello");
cout<<*ps2<<endl;

So it that means that "placement new" and "operator new" are obsolete?

c++
Edit
Report