Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't std::bind and boost::bind be used interchangeably in this Boost.Asio tutorials
    primarykey
    data
    text
    <p>I was trying the differents tutorials in Boost.Asio documentation and tried to replace boost components with C++11 ones. However, I got an error using std::bind in <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/tutorial/tuttimer5.html" rel="nofollow noreferrer">Timer.5 - Synchronising handlers in multithreaded programs</a>. Here is the code proposed:</p> <pre><code>#include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/thread/thread.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; class printer { /* Not relevent here */ }; int main() { boost::asio::io_service io; printer p(io); boost::thread t(boost::bind(&amp;boost::asio::io_service::run, &amp;io)); io.run(); t.join(); return 0; } </code></pre> <p>I tried to replace <code>boost::thread</code> by <code>std::thread</code> and <code>boost::bind</code> by <code>std::bind</code>. Here is my code:</p> <pre><code>#include &lt;functional&gt; #include &lt;iostream&gt; #include &lt;thread&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; class printer { /* Not relevent here */ }; int main() { boost::asio::io_service io; printer p(io); std::thread t(std::bind(&amp;boost::asio::io_service::run, &amp;io)); io.run(); t.join(); } </code></pre> <p>When compiling with GCC 4.7, I got this compile-time error:</p> <pre><code>g++ -std=c++0x main.cpp -lboost_system -lboost_date_time -lpthread main.cpp: In function ‘int main()’: main.cpp:52:60: erreur: no matching function for call to ‘bind(&lt;unresolved overloaded function type&gt;, boost::asio::io_service*)’ main.cpp:52:60: note: candidates are: /usr/include/c++/4.6/functional:1444:5: note: template&lt;class _Functor, class ... _ArgTypes&gt; typename std::_Bind_helper::type std::bind(_Functor&amp;&amp;, _ArgTypes&amp;&amp; ...) /usr/include/c++/4.6/functional:1471:5: note: template&lt;class _Result, class _Functor, class ... _ArgTypes&gt; typename std::_Bindres_helper::type std::bind(_Functor&amp;&amp;, _ArgTypes&amp;&amp; ...) </code></pre> <p>Where is this error comming from, taking into account that I did not use any <code>boost::asio::placeholders</code> (as explain in this stackoverflow question <a href="https://stackoverflow.com/questions/8924149/should-stdbind-be-compatible-with-boostasio">Should std::bind be compatible with boost::asio?</a>)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload