Should std::bind be compatible with boost::asio?

前端 未结 1 834
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 10:30

I am trying to adapt one of the boost::asio examples to use c++11 / TR1 libraries where possible. The original code looks like this:

void start_accept()
{ 
          


        
相关标签:
1条回答
  • 2020-12-25 10:55

    I now have a solution

    The problem is that when I first tried to switch to std::bind and std::shared_ptr I was still using the boost::asio::placeholders with std::bind, this resulted in a large amount of template compiler errors, so I then tried to switch piecemeal.

    I first tried switching just boost::shared_ptr to std::shared_ptr, this failed because boost::bind will not work with std::shared_ptr with out a specialisation of the template get_pointer<typename T> for std::shared_ptr (see: How to resolve conflict between boost::shared_ptr and using std::shared_ptr?).

    After switching to std::shared_ptr I then switched to std::bind, this time using the std::placeholders, (thanks richard) the example code now compiles and works correctly.

    In order to use std::bind with boost::asio make sure that std::shared_ptr and the std::placeholders are also used.

    0 讨论(0)
提交回复
热议问题