提升unique_ptr Deletor

Ton*_*ion 5 c++ boost

如果我想创建一个unique_ptr类型QueueList(一些自定义对象),我该如何为它定义一个deletor,或者我是否已经使用了一个模板'Deletor'?

我想要一个,unique_ptr所以我可以安全地在线程之间传输对象,而不必在线程之间共享它.

编辑

boost::interprocess::unique_ptr<QueueList> LIST;  ///FAILS to COMPILE!!!

LIST mylist;
Run Code Online (Sandbox Code Playgroud)

编译器:MS Visual Studio 2003

错误:

错误C2976:'boost :: interprocess :: unique_ptr':模板参数太少

错误C2955:'boost :: interprocess :: unique_ptr':使用类模板需要模板参数列表:请参阅'boost :: interprocess :: unique_ptr'的声明

小智 9

这是一个简单的删除类,只在任何给定对象上调用delete:

template<typename T> struct Deleter {
    void operator()(T *p)
    {
        delete p;
    }
};
Run Code Online (Sandbox Code Playgroud)

然后,您可以将其与unique_ptr一起使用,如下所示:

boost::interprocess::unique_ptr<QueueList, Deleter<QueueList> > LIST;
Run Code Online (Sandbox Code Playgroud)