dimanche 26 avril 2015

Move constructor is not called with boost::asio::ip::tcp::socket

I think in the following code should work but it generates a compilation error:

error C2248: 'boost::asio::basic_io_object<SocketService,true>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<SocketService,true>'

It seems that the move constructor is not called implicitly.

#include <thread>
#include <boost/asio.hpp>

void Func(boost::asio::ip::tcp::socket sock) {}

int main()
{
    boost::asio::io_service service;
    boost::asio::ip::tcp::socket sock(service);
    std::thread(Func, std::move(sock)).detach(); // error C2248
    //Func(std::move(sock)); // OK
    return 0;
}

I also tried to define BOOST_ASIO_HAS_MOVE as suggested in this question but it didn't work.

Is there any workaround for this?

Experimented with VS2013 update 3 and boost 1.56.0.

Aucun commentaire:

Enregistrer un commentaire