Asio v1.20 standalone library server example shows how asio::ssl::stream
is moved from the server class to the session class. When I try to compile the example, it throws me an error:
/home/user/tmp/tmp.ZxZvgK7sGZ/main.cpp: In constructor ‘session::session(asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp> >)’:
/home/user/tmp/tmp.ZxZvgK7sGZ/main.cpp:23:34: error: use of deleted function ‘asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp> >::stream(const asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp> >&)’
23 | : socket_(std::move(socket))
| ^
In file included from /usr/include/asio/ssl.hpp:22,
from /home/user/tmp/tmp.ZxZvgK7sGZ/main.cpp:15:
/usr/include/asio/ssl/stream.hpp:63:7: note: ‘asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp> >::stream(const asio::ssl::stream<asio::basic_stream_socket<asio::ip::tcp> >&)’ is implicitly deleted because the default definition would be ill-formed:
63 | class stream :
| ^~~~~~
/usr/include/asio/ssl/stream.hpp:63:7: error: ‘asio::detail::noncopyable::noncopyable(const asio::detail::noncopyable&)’ is private within this context
I understand that I can't move my asio::ssl::stream
because it is noncopyable, or am I missing something? How to make the example above compile?
I tried to use Asio standalone library with ASIO_HAS_MOVE as well.
Compiler:
$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
PROBLEM & SOLUTION
I installed the Asio library as a Debian package libasio-dev
for which I didn't check the version. It is v1.18. I installed it from source now and it works, as @dewaffled pointed out.