[Boost-bugs] [Boost C++ Libraries] #4744: Some handler arguments are not passed as lvalues

Subject: [Boost-bugs] [Boost C++ Libraries] #4744: Some handler arguments are not passed as lvalues
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-10-16 12:17:05


#4744: Some handler arguments are not passed as lvalues
------------------------------+---------------------------------------------
 Reporter: chris_kohlhoff | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.44.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 Some handler arguments (e.g. those passed by async_read() and other
 composed asynchronous operations) are not being passed as lvalues. This
 prevents interoperability with some implementations of std::tr1::bind.

 The following program should compile correctly:

 {{{
 #include <boost/asio.hpp>
 #include <boost/regex.hpp>

 struct handler
 {
   template <typename T1, typename T2>
   void operator()(T1&, T2&) {}
 };

 class match_char
 {
 public:
   explicit match_char(char c) : c_(c) {}

   template <typename Iterator>
   std::pair<Iterator, bool> operator()(
       Iterator begin, Iterator end) const
   {
     Iterator i = begin;
     while (i != end)
       if (c_ == *i++)
         return std::make_pair(i, true);
     return std::make_pair(i, false);
   }

 private:
   char c_;
 };

 namespace boost {
   namespace asio {
     template <> struct is_match_condition<match_char>
       : public boost::true_type {};
   } // namespace asio
 } // namespace boost

 int main()
 {
   boost::asio::io_service io_service;
   boost::asio::ip::tcp::socket sock(io_service);
   char buf[1024]= "";
   boost::asio::streambuf sb;

   boost::asio::async_read(sock, boost::asio::buffer(buf), handler());
   boost::asio::async_write(sock, boost::asio::buffer(buf), handler());
   boost::asio::async_read(sock, sb, handler());
   boost::asio::async_write(sock, sb, handler());
   boost::asio::async_read_until(sock, sb, '\n', handler());
   boost::asio::async_read_until(sock, sb, "\n", handler());
   boost::asio::async_read_until(sock, sb, boost::regex("\n"), handler());
   boost::asio::async_read_until(sock, sb, match_char('\n'), handler());
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4744>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC