Should I see significant differences between std :: bind and boost :: bind?

I am studying C ++ 11 support on g ++ - 4.7 (Ubuntu / Linaro 4.7.3-2ubuntu ~ 12.04 to be specific) and I seem to be detecting differences.

In particular, if I comment on #include <boost/bind.hpp> and systematically replace the occurrences of boost::bind with std::bind in the ASIS as up client example (for example, http://www.boost.org/doc/libs /1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp ), the program no longer compiles.

Any explanation for this?

+6
source share
2 answers
 #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::*

+7
source

It seems that boost::asio::placeholders cannot be used with std::bind . In the example you connected to, the first boost::bind call occurs in the following code:

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

Just replacing boost::bind with std::bind leads to a bunch of errors. To compile it, 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)); 

Please note that I did not confirm that after making these changes, the code is functionally the same, only it compiles.

+4
source

Source: https://habr.com/ru/post/948493/


All Articles