std :: bind是否一般使用只移动类型,特别是std :: unique_ptr? [英] Does std::bind work with move-only types in general, and std::unique_ptr in particular?

查看:558
本文介绍了std :: bind是否一般使用只移动类型,特别是std :: unique_ptr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要使用boost :: asio并尝试编译以下代码:

  std :: unique_ptr< buffer_t> buffer = buffers.pop(); 
std :: function< void(const boost :: system :: error_code& size_t)> t = std :: bind(& tcp_client :: handle_read_done,
this,
std :: placeholders :: _ 1,
std :: placeholders :: _ 2,
std: :move(buffer));

如果我排除std :: move(buffer),一切都很好,当然从签名



当试图将它传递给boost :: asio :: async_read_some时,它会引发对象上隐式删除的函数从std :: bind返回,对tuple上的删除函数,我假设是因为可移动性,以及很多boost具体错误。如果我只是试图将其分配到一个std ::函数,它应该匹配boost调用的签名,我得到那些相同的元组错误,所以我猜他们是相同的。只要将std :: bind的结果赋给auto就不会产生编译器错误,但是当然我不能调用任何东西。



我做错了什么?下面是试图分配 std :: function< void(const boost :: system :: error_code&,size_t)>

$ b时的输出
$ b

  /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2 /../../../../ include /c++/4.6.2/functional:在静态成员函数'static void std :: _ Function_handler  /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/。 ./../../../include/c++/4.6.2/functional:2148:6:实例化为'std :: function< _Res(_ArgTypes ...)> :: function(_Functor,typename std :: enable_if<(! std :: is_integral< _Functor> :: value),std :: function< _Res(_ArgTypes ...)> :: _ Useless> :: type)[with _Functor = std :: _Bind< std :: _ Mem_fn< void rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul>>)& net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul>>)> ;, _Res = void,_ArgTypes = const boost :: system :: error_code& long,unsigned int},typename std :: enable_if<(!std :: is_integral< _Functor> :: value),std :: function< _Res(_ArgTypes ...)> ;: :_Useless> :: type = std :: function< void(const boost :: system :: error_code& long unsigned int)> :: _ Useless]'
/ home / max / dev / rcon / src / net / tcp_client.cpp:98:34:从这里实例化
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/ c ++ / 4.6.2 / functional:1778:2:错误:没有匹配调用'(std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *) :: error_code& long,unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> >)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> ;)(const boost :: system :: error_code& long,unsigned int)'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../ ../include/c++/4.6.2/functional:1130:11:注意:候选人是:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../ .. /../../include/c++/4.6.2/functional:1201:2:note:template< class ... _Args,class _Result> _Result std :: _Bind< _Functor(_Bound_args ...)> :: operator()(_Args&& ...)[with _Args = {_Args ...},_Result = _Result,_Functor = std :: _ Mem_fn< ; void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul& _Bound_args = {rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1215 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_ Args& ...)const [with _Args = {_Args ...},_Result = _Result,_Functor = std :: _Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1229 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_ Args& ...)volatile [with _Args = {_Args ...},_Result = _Result,_Functor = std :: _Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1243 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_Args& ...)const volatile [with _Args = {_Args ...},_Result = _Result,_Functor = std: :_Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ;,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:In静态成员函数'static void std :: _ Function_base :: _ Base_manager< _Functor> :: _ M_clone(std :: _ Any_data& const std :: _ Any_data& std :: false_type)[with _Functor = std :: _ Bind& _Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> (rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul>>)>,std :: false_type = std :: integral_constant< bool,false>]':
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include /c++/4.6.2/functional:1652:8:从'static bool std :: _ Function_base :: _ Base_manager< _Functor> :: _ M_manager(std :: _ Any_data& const std :: _ Any_data& std :: _ Manager_operation) [with _Functor = std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> >)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> ;]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:2149: 6:从'std :: function< _Res(_ArgTypes ...)>实例化:: function(_Functor,typename std :: enable_if<(!std :: is_integral< _Functor> :: value),std :: function< _Res(_ArgTypes ...)> :: _ Useless> :: type)[with _Functor = std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *) :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul>>)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul>)> ;, _Res = void,_ArgTypes = {const boost :: system :: error_code& long unsigned int},typename std :: enable_if<(!std :: is_integral< _Functor> :: value),std :: function< _Res(_ArgTypes ...)> :: _ Useless> :: type = std :: function< void :system :: error_code& long unsigned int)> :: _ Useless]'
/home/max/dev/rcon/src/net/tcp_client.cpp:98:34:从这里实例化
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1616:4:错误:使用删除函数'std :: _Bind< _Functor(_Bound_args ...)> :: _Bind(const std :: _Bind< _Functor(_Bound_args ...)&)&)[with _Functor = std :: _ Mem_fn < :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> >)>,_Bound_args = {rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2> ;, std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _ Bind< _Functor(_Bound_args ...)> = std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< char,10240ul>)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >)>]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/功能:1189:7:错误:'std :: _ Bind< _Functor(_Bound_args ...)> :: _ Bind(const std :: _ Bind< _Functor(_Bound_args ...)&) :: _ Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> >,_Bound_args = {rcon :: net :: tcp_client *,std :: _ placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _ Bind< _Functor(_Bound_args ...)> = std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul>)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >)>]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../。 ./../include/c++/4.6.2/functional:1189:7:错误:使用删除的函数'constexpr std :: tuple< < template-parameter-1-1> > :: tuple(const std :: tuple<< template-parameter-1-1>&)[with _Elements = {rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _占位符< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: tuple< < template-parameter-1-1> > = std :: tuple ,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'
在/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2中包含的文件中/ functional:56:0,
从/home/max/dev/rcon/include/net/tcp_client.hpp:4,
从/ home / max / dev / rcon / src / net / tcp_client .cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple: 249:17:error:'constexpr std :: tuple< < template-parameter-1-1> > :: tuple(const std :: tuple<< template-parameter-1-1>&)[with _Elements = {rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _占位符< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: tuple< < template-parameter-1-1> > = std :: tuple ,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../。 ./include/c++/4.6.2/tuple:249:17:错误:使用删除的函数'constexpr std :: _ Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _ Tuple_impl< _Idx ,_Head,_Tail ...>&)[with long unsigned int _Idx = 0ul,_Head = rcon :: net :: tcp_client *,_Tail = {std :: _ Placeholder< 1>,std :: _ Placeholder& ,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl <0ul,rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170 :17:error:'constexpr std :: _Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _Tuple_impl< _Idx,_Head,_Tail ...>&)[with long unsigned int _Idx = 0ul,_Head = rcon :: net :: tcp_client *,_Tail = {std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _ Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl <0ul,rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../。 ./include/c++/4.6.2/tuple:170:17:error:使用删除的函数'constexpr std :: _ Tuple_impl< _Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _ Tuple_impl< _Idx ,_Head,_Tail ...>&)[with long unsigned int _Idx = 1ul,_Head = std :: _占位符< 1>,_Tail = {std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl <1ul,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170 :17:error:'constexpr std :: _Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _Tuple_impl< _Idx,_Head,_Tail ...& _Idx = 1ul,_Head = std :: _占位符<1>,_Tail = {std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl <1ul,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../。 ./include/c++/4.6.2/tuple:170:17:错误:使用删除的函数'constexpr std :: _ Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _ Tuple_impl< _Idx ,_Head,_Tail ...>&)[with long unsigned int _Idx = 2ul,_Head = std :: _占位符< 2> ;, _Tail = {std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl< 2ul,std :: _占位符< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170 :17:error:'constexpr std :: _Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _Tuple_impl< _Idx,_Head,_Tail ...& _Idx = 2ul,_Head = std :: _占位符< 2>,_Tail = {std :: unique_ptr< std :: array< unsigned char,10240ul> >},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl< 2ul,std :: _占位符< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../。 ./include/c++/4.6.2/tuple:170:17:error:使用删除的函数'constexpr std :: _ Tuple_impl< _Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _ Tuple_impl< _Idx ,_Head,_Tail ...>&)[with long unsigned int _Idx = 3ul,_Head = std :: unique_ptr< std :: array< unsigned char,10240ul> >,_Tail = {},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl< 3ul,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170 :17:error:'constexpr std :: _Tuple_impl <_Idx,_Head,_Tail ...> :: _ Tuple_impl(const std :: _Tuple_impl< _Idx,_Head,_Tail ...>&)[with long unsigned int _Idx = 3ul,_Head = std :: unique_ptr< std :: array< unsigned char,10240ul> >,_Tail = {},std :: _Tuple_impl< _Idx,_Head,_Tail ...> = std :: _Tuple_impl< 3ul,std :: unique_ptr< std :: array< unsigned char,10240ul> > >]'被隐式删除,因为默认定义将是错误的:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../。 ./include/c++/4.6.2/tuple:170:17:error:使用删除的函数'std :: _ Head_base< 3ul,std :: unique_ptr< std :: array< unsigned char,10240ul> >,false> :: _ Head_base(const std :: _ Head_base< 3ul,std :: unique_ptr< std :: array< unsigned char,10240ul> ;,>&)'
/ usr / gcc / x86_64-unknown-linux-gnu / 4.6.2 /../../../../ include / c ++ / 4.6.2 / tuple:91:12:error:'std :: _ Head_base <3ul, std :: unique_ptr< std :: array< unsigned char,10240ul> >,false> :: _ Head_base(const std :: _ Head_base< 3ul,std :: unique_ptr< std :: array< unsigned char,10240ul>>,false>&)'被隐含地删除,因为默认定义将是错误:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:91 :12:错误:使用已删除的函数'std :: unique_ptr< _Tp,_Dp> :: unique_ptr(const std :: unique_ptr< _Tp,_Dp>&)[with _Tp = std :: array< unsigned char,10240ul> ,_Dp = std :: default_delete< std :: array< unsigned char,10240ul> >,std :: unique_ptr< _Tp,_Dp> = std :: unique_ptr< std :: array< unsigned char,10240ul> >]'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/unique_ptr .h:256:7:错误:在此声明

更新:



我知道上面似乎不工作。但是,那么,应该不是下面的工作呢?

  std :: unique_ptr< buffer_t> buffer = buffers.pop(); 

auto t = std :: bind(& tcp_client :: handle_read_done,
this,
std :: placeholders :: _ 1,
std :: placeholder: :_2,
std :: move(buffer));
size_t var = 10;
boost :: system :: error_code code;
t(code,var);

handle_read_done 的签名



  void tcp_client :: handle_read_done(const boost :: system :: error_code& error,size_t bytes_read,std :: unique_ptr< buffer_t>缓冲区)

感觉我缺少很明显的东西。



错误讯息:

  / home / max / dev / rcon /src/net/tcp_client.cpp:在成员函数'void rcon :: net :: tcp_client :: handle_connect_done(const boost :: system :: error_code& const string&)':
/ home / max / dev / rcon / src / net / tcp_client.cpp:101:15:错误:无匹配调用'(std :: _ Bind< std :: _ Mem_fn< void(rcon :: net :: tcp_client :: *) boost :: system :: error_code& long,long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul>>)>(rcon :: net :: tcp_client *,std :: _ Placeholder< 1> ,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul>>)>)(boost :: system :: error_code& size_t&)'
/ usr /lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1130:11:注:候选人是:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1201:2:note:template< ; class ... _Args,class _Result> _Result std :: _Bind< _Functor(_Bound_args ...)> :: operator()(_Args&& ...)[with _Args = {_Args ...},_Result = _Result,_Functor = std :: _ Mem_fn< ; void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul& _Bound_args = {rcon :: net :: tcp_client *,std :: _ Placeholder< 1>,std :: _ Placeholder< 2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1215 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_ Args& ...)const [with _Args = {_Args ...},_Result = _Result,_Functor = std :: _Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1229 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_ Args& ...)volatile [with _Args = {_Args ...},_Result = _Result,_Functor = std :: _Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1243 :2:note:template< class ... _Args,class _Result> _Result std :: _ Bind< _Functor(_Bound_args ...)> :: operator()(_Args& ...)const volatile [with _Args = {_Args ...},_Result = _Result,_Functor = std: :_Mem_fn< void(rcon :: net :: tcp_client :: *)(const boost :: system :: error_code& long unsigned int,std :: unique_ptr< std :: array< unsigned char,10240ul> ;,_Bound_args = {rcon :: net :: tcp_client *,std :: _占位符<1>,std :: _占位符<2>,std :: unique_ptr< std :: array< unsigned char,10240ul> >}]


解决方案

std :: bind 在只移动类型下运行良好。然而,它在过程中创建一个只移动函数。 std :: function 需要一个可构造的复制函子。这听起来像 boost :: asio 也。



当你调用只移动 bind 函数,它将其绑定参数作为lvalues传递给目标操作符()。因此,如果你的一个绑定参数是move-only,目标operator()必须采用该参数(可能const)lvalue引用。


I'm trying to use boost::asio and run into a bit of a quagmire.

I'm trying to compile the following code:

std::unique_ptr<buffer_t> buffer = buffers.pop();
std::function<void(const boost::system::error_code&, size_t)> t = std::bind(&tcp_client::handle_read_done,
                                                                            this,
                                                                            std::placeholders::_1,
                                                                            std::placeholders::_2,
                                                                            std::move(buffer));

Everything works fine if I exclude the std::move(buffer), of course from both the signature of handle_read_done and as a passed argument in std::bind.

When trying to pass it into boost::asio::async_read_some it complains of implicitly deleted functions on the object returned from std::bind, on deleted functions on tuple which I assume are because of the movability, as well as a lot of boost specific errors. If I just try to assign it into a std::function which should match the signature that boost calls, I get those same tuple errors, so I guess they are the same ones. Just assigning the result of std::bind to auto yields no compiler error, but of course I can't call anything on it.

What am I doing wrong? Below is the output from when trying to assign to std::function<void(const boost::system::error_code&,size_t)>

/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional: In static member function ‘static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes ...) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _ArgTypes = {const boost::system::error_code&, long unsigned int}]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:2148:6:   instantiated from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Res = void, _ArgTypes = {const boost::system::error_code&, long unsigned int}, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type = std::function<void(const boost::system::error_code&, long unsigned int)>::_Useless]’
/home/max/dev/rcon/src/net/tcp_client.cpp:98:34:   instantiated from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1778:2: error: no match for call to ‘(std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>) (const boost::system::error_code&, long unsigned int)’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1130:11: note: candidates are:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1201:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1215:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1229:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1243:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional: In static member function ‘static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::false_type) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, std::false_type = std::integral_constant<bool, false>]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1652:8:   instantiated from ‘static bool std::_Function_base::_Base_manager<_Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:2149:6:   instantiated from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Res = void, _ArgTypes = {const boost::system::error_code&, long unsigned int}, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type = std::function<void(const boost::system::error_code&, long unsigned int)>::_Useless]’
/home/max/dev/rcon/src/net/tcp_client.cpp:98:34:   instantiated from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1616:4: error: use of deleted function ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const std::_Bind<_Functor(_Bound_args ...)>&) [with _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Bind<_Functor(_Bound_args ...)> = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1189:7: error: ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const std::_Bind<_Functor(_Bound_args ...)>&) [with _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Bind<_Functor(_Bound_args ...)> = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1189:7: error: use of deleted function ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple< <template-parameter-1-1> >&) [with _Elements = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::tuple< <template-parameter-1-1> > = std::tuple<rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:56:0,
                 from /home/max/dev/rcon/include/net/tcp_client.hpp:4,
                 from /home/max/dev/rcon/src/net/tcp_client.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:249:17: error: ‘constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple< <template-parameter-1-1> >&) [with _Elements = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::tuple< <template-parameter-1-1> > = std::tuple<rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:249:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 0ul, _Head = rcon::net::tcp_client*, _Tail = {std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 0ul, _Head = rcon::net::tcp_client*, _Tail = {std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 1ul, _Head = std::_Placeholder<1>, _Tail = {std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<1ul, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 1ul, _Head = std::_Placeholder<1>, _Tail = {std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<1ul, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 2ul, _Head = std::_Placeholder<2>, _Tail = {std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<2ul, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 2ul, _Head = std::_Placeholder<2>, _Tail = {std::unique_ptr<std::array<unsigned char, 10240ul> >}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<2ul, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: use of deleted function ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 3ul, _Head = std::unique_ptr<std::array<unsigned char, 10240ul> >, _Tail = {}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&) [with long unsigned int _Idx = 3ul, _Head = std::unique_ptr<std::array<unsigned char, 10240ul> >, _Tail = {}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> > >]’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:170:17: error: use of deleted function ‘std::_Head_base<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> >, false>::_Head_base(const std::_Head_base<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> >, false>&)’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:91:12: error: ‘std::_Head_base<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> >, false>::_Head_base(const std::_Head_base<3ul, std::unique_ptr<std::array<unsigned char, 10240ul> >, false>&)’ is implicitly deleted because the default definition would be ill-formed:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/tuple:91:12: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = std::array<unsigned char, 10240ul>, _Dp = std::default_delete<std::array<unsigned char, 10240ul> >, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<std::array<unsigned char, 10240ul> >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/unique_ptr.h:256:7: error: declared here

Update:

I understand that the above doesn't seem to work. But then, shouldn't the following work?

  std::unique_ptr<buffer_t> buffer = buffers.pop();

  auto t = std::bind(&tcp_client::handle_read_done,
             this,
             std::placeholders::_1,
             std::placeholders::_2,
             std::move(buffer));
  size_t var = 10;
  boost::system::error_code code;
  t(code, var);

Where the signature of handle_read_done is

void tcp_client::handle_read_done(const boost::system::error_code & error, size_t bytes_read, std::unique_ptr<buffer_t> buffer)

It feels like I am missing something very obvious.

Error message:

/home/max/dev/rcon/src/net/tcp_client.cpp: In member function ‘void rcon::net::tcp_client::handle_connect_done(const boost::system::error_code&, const string&)’:
/home/max/dev/rcon/src/net/tcp_client.cpp:101:15: error: no match for call to ‘(std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>) (boost::system::error_code&, size_t&)’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1130:11: note: candidates are:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1201:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1215:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1229:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1243:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _Bound_args = {rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >}]

解决方案

std::bind works fine with move-only types. However it creates a move-only functor in the process. std::function requires a copy constructible functor. It sounds like boost::asio does too.

When you call the move-only bind functor, it will pass its bound arguments as lvalues to the target operator(). So if one of your bound arguments is move-only, the target operator() must take that argument by (possibly const) lvalue reference.

这篇关于std :: bind是否一般使用只移动类型,特别是std :: unique_ptr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆