4 ms·
See also the proposal for language-support for scoped allocations: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2685r0.html https://www.open-std.o
by gavinray 3y ago
See also the proposal for language-support for scoped allocations:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2685r0.html https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p26...
There are some issues with PMR usage that it hopes to resolve, for example:
struct Aggregate {
std::pmr::string data1;
std::pmr::string data2;
std::pmr::string data3;
};
std::pmr::polymorphic_allocator a1;
Aggregate ag = {{"Hello", a1}, {"World", a1}, {"!", a1}};
std::pmr::vector<Aggregate> va(a1);
va.emplace_back(std::move(ag)); // Correct allocator retained by moves
va.emplace_back(ag); // Error, copied lvalue has wrong allocator
va.resize(5); // Error, new values have wrong allocator
va.resize(1); // OK, remove all objects with bad allocators
The proposed syntax is via a "using" keyword:
std::pmr::polymorphic_allocator a4;
ScopeAggregate s1 using a4 {"Hello"};