You can do it using std::allocator_traits
.
The point of removing the construct method is because the allocator traits already has that method, and the STL containers use std::allocator_traits::construct
anyway.
Documentation in cppreference
And here is a little example: (Alloc
is any allocator)
Alloc a{};
std::allocator_traits<Alloc>::pointer i = std::allocator_traits<Alloc>::allocate(a, allocated_size);
// You use the construct and destroy methods from the allocator traits
std::allocator_traits<Alloc>::construct(a, i, value_to_construt);
std::allocator_traits<Alloc>::destroy(a, i);
std::allocator_traits<Alloc>::deallocate(a, i, allocated_size);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…