std::allocator construct/destroy vs. placement new/p->~T()

前端 未结 2 1620
庸人自扰
庸人自扰 2020-12-31 15:03

For a project of mine, I am writing some STL containers from scratch (I have my reasons). Since I am mimicking the functionality and interfaces of the STL so closely I am do

2条回答
  •  佛祖请我去吃肉
    2020-12-31 15:17

    This is just to hide the details of allocation in a method. i.e., we are providing the APIs for construction and destruction, in the future we can change the implementation. Now we are using placement new to allocate the memory, in the future if we want to change the allocation we just have to change these two methods.

提交回复
热议问题