9

allocator は「placement new」や「operator new」と同じ働きをしているようです。そしてそのインターフェースはより便利です。

例えば:

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

に書き換えることができます

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

つまり、「placement new」と「operator new」は廃止されたということですか。

4

1 に答える 1