Should I be seeing significant differences between std::bind and boost::bind?

无人久伴 提交于 2019-12-05 08:08:55
#include <functional>
namespace boost {
    namespace asio {
        namespace stdplaceholders {
            static decltype ( :: std :: placeholders :: _1 ) & error = :: std :: placeholders :: _1;
            static decltype ( :: std :: placeholders :: _2 ) & bytes_transferred = :: std :: placeholders :: _2;
            static decltype ( :: std :: placeholders :: _2 ) & iterator = :: std :: placeholders :: _2;
            static decltype ( :: std :: placeholders :: _2 ) & signal_number = :: std :: placeholders :: _2;
        }
    }
}

and use boost::asio::stdplaceholders::* instead of boost::asio::placeholders::*

It looks like boost::asio::placeholders cannot be used in conjunction with std::bind. In the example you've linked to, the first call to boost::bind occurs in the following code:

resolver_.async_resolve(query,
    boost::bind(&client::handle_resolve, this,
      boost::asio::placeholders::error,
      boost::asio::placeholders::iterator));

Simply replacing boost::bind with std::bind leads to a bunch of errors. To make it compile you need to replace boost::asio::placeholders with std::placeholders.

resolver_.async_resolve(query,
    std::bind(&client::handle_resolve, this,
      std::placeholders::_1,
      std::placeholders::_2));

Note that I haven't verified that the code is functionally the same after making these changes, only that it compiles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!