Using std::make_unique with a custom deleter

后端 未结 3 1158
栀梦
栀梦 2020-12-17 08:02

In using std::unique_ptr with a custom deleter I desire to use std::make_unique rather than a raw new. I am using VC++2013. It appears to me that

3条回答
  •  一向
    一向 (楼主)
    2020-12-17 08:12

    As far as I know there is no make_unique function in the C++11 standard. See

    • Why does C++11 have `make_shared` but not `make_unique`
    • make_unique and perfect forwarding

    So I would assume that the make_unique is an implementation from Microsoft that is at least not included in the standard.

    But nevertheless you can use a custom deleter with unique_ptr. When using unique_ptr you have to specify the type of the deleter as a second template argument and then pass an appropriate object to the constructor.

提交回复
热议问题