Я пытаюсь использовать 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), конечно, как из сигнатуры handle_read_done, так и в качестве переданного аргумента в std :: bind.
При попытке передать его в boost :: asio :: async_read_someон жалуется на неявно удаленные функции на объекте, возвращаемом из std :: bind, на удаленные функции на кортеже, которые, как я полагаю, вызваны подвижностью, а также множеством ошибок, связанных с повышением.Если я просто попытаюсь присвоить его в std :: function, которая должна соответствовать сигнатуре, вызывающей буст-вызовы, я получу те же самые ошибки кортежа, так что я предполагаю, что они одинаковые.Просто присвоение результата std :: bind auto не приводит к ошибке компилятора, но, конечно, я не могу ничего вызвать для него.
Что я делаю не так?Ниже приведен вывод при попытке присвоить 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
Обновление:
Я понимаю, что приведенное выше не похоже на работу.Но тогда разве не должна работать следующая работа?
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);
Где подпись handle_read_done
void tcp_client::handle_read_done(const boost::system::error_code & error, size_t bytes_read, std::unique_ptr<buffer_t> buffer)
Такое ощущение, что я упускаю что-то очень очевидное.
Сообщение об ошибке:
/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> >}]