6

I'm exploring the support for C++11 on the g++-4.7 (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences.

In particular, if I comment out #include <boost/bind.hpp> and systematically replace occurrences of boost::bind with std::bind in the Boost ASIO async client example (taken from 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?

Praetorian
  • 106,671
  • 19
  • 240
  • 328
BD at Rivenhill
  • 12,395
  • 10
  • 46
  • 49
  • 2
    Can you please make a replacement that fails (preferably a single replacement) and post the modified code along with the compiler error? – Praetorian Jul 01 '13 at 19:39
  • I remember having seen different behaviour with nested binds. Don't recall the specifics right now. However, this is _not_ what you are running into here. – sehe Jul 01 '13 at 21:34

2 Answers2

7
#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::*

pal
  • 618
  • 4
  • 9
4

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.

Praetorian
  • 106,671
  • 19
  • 240
  • 328