Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::unique_ptr使用带有少量参数的自定义删除器_C++_C++11_Unique Ptr - Fatal编程技术网

C++ std::unique_ptr使用带有少量参数的自定义删除器

C++ std::unique_ptr使用带有少量参数的自定义删除器,c++,c++11,unique-ptr,C++,C++11,Unique Ptr,我想知道是否有可能为std::unique_ptr指定一个以上参数(标准deleter签名)的自定义deleter。我知道std::shared_ptr存在std::bind的解决方法,这使它成为可能,但是std::unique_ptr存在一些技巧吗 对我来说,这似乎不是因为: 类型要求 -Deleter必须是FunctionObject或FunctionObject的左值引用或function的左值引用,可使用 类型为unique_ptr::pointer的参数 void my_free(in

我想知道是否有可能为std::unique_ptr指定一个以上参数(标准deleter签名)的自定义deleter。我知道std::shared_ptr存在std::bind的解决方法,这使它成为可能,但是std::unique_ptr存在一些技巧吗

对我来说,这似乎不是因为:

类型要求 -Deleter必须是FunctionObject或FunctionObject的左值引用或function的左值引用,可使用 类型为unique_ptr::pointer的参数

void my_free(int*p,int x,int y){

std::cout使用
std::bind
创建一个参数函数对象以传递给
std::unique\u ptr
类型
void my_free(int* p, int x, int y){
  std:: cout << x << " " << y << "\n";
}
int main()
{
    auto my_deleter = std::bind(my_free, std::placeholders::_1, 1, 2) ;
    auto my_lambda = [](int* t) { my_free(t, 3, 4); };
    std::unique_ptr<int, decltype(my_deleter)> ptr(new int, my_deleter);
    std::unique_ptr<int, decltype(my_lambda)> ptr2(new int, my_lambda);
    return 0;
}