jeudi 31 janvier 2019

How to convert std::array to boost::asio::buffer?

I am trying to convert an std::array to an boost::asio::buffer to use it for async_read_some, but I always get some errors:

Here is my code sample:

array<char, 16> data;
tcpSocket.async_read_some(buffer(data), [data](const boost::system::error_code& ec, size_t ammountOfBytes) {
if (ec) {
    cout << "Read failed with message: " << ec.message() << endl;
}
else {
    cout.write(data.data(), ammountOfBytes);
}
});

This are the errors I get:

Error   C2661   'boost::asio::detail::buffer_sequence_adapter_base::init_native_buffer': no overloaded function takes 1 arguments
Error   C2440   '<function-style-cast>': cannot convert from 'const boost::asio::const_buffers_1' to 'boost::asio::mutable_buffer'

I find it weird that all examples I see online use the same syntax.

Aucun commentaire:

Enregistrer un commentaire