boost::asio::read_until w/ boost::function

I'm having some trouble resolving the call to read_until (see snippet below) Is there some reason I am not be able to use a boost::function as the MatchCondition object? Thanks, ...m _______________ [MyClass.h] class MyClass { ... typedef boost::asio::buffers_iterator<boost::asio::streambuf::const_buffers_type> t_Iterator; typedef std::pair<t_Iterator, bool> t_ConditionPair; boost::asio::serial_port _port; boost::asio::streambuf _readBuffer; t_ConditionPair myCondition(t_Iterator begin, t_Iterator end); void doRead(); ... }; [MyClass.cpp] MyClass::t_ConditionPair myCondition(t_Iterator begin, t_Iterator end) { t_ConditionPair theCondition; theCondition.first = end; theCondition.second = true; return theCondition; } void MyClass::doRead() { ... boost::asio::read_until( _port, _readBuffer, boost::bind( &MyClass::myCondition, this, _1, _2 ) ); ... }

On Sat, Feb 20, 2010 at 10:56 AM, Igor R <boost.lists@gmail.com> wrote:
I'm having some trouble resolving the call to read_until (see snippet below)
Is there some reason I am not be able to use a boost::function as the MatchCondition object?
It compiles well with MSVC9.0
As a workaround, try assigning the result of the bind to a boost::function<> object of the appropriate type first, and then passing that boost::function<> object by value into the asio method Not sure if it will work, but if nothing else it might get the compiler to give you a different error and you can figure something out.

Thanks for your input. Unfortunately; no dice. It still doesn't compile (below), and the error(also below) provides little insight in my relatively inexperienced assessment. I have a feeling that the enable_if mechanism is not behaving properly on my particular system. (the fact that others have successfully compiled this implies that the boost::function must have the correct signature to satisfy the enable_if....) ----error /usr/local/include/boost/asio/read_until.hpp: In instantiation of `boost::asio::detail::has_result_type<boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)> >': /usr/local/include/boost/asio/read_until.hpp:75: instantiated from `boost::asio::is_match_condition<boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)> >' /usr/local/include/boost/utility/enable_if.hpp:36: instantiated from `boost::enable_if<boost::asio::is_match_condition<boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)> >, void>' ../src/temp.cpp:56: instantiated from here /usr/local/include/boost/asio/read_until.hpp:60: error: call of overloaded `helper(const boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>&)' is ambiguous /usr/local/include/boost/asio/read_until.hpp:57: note: candidates are: static boost::asio::detail::has_result_type<T>::big boost::asio::detail::has_result_type<T>::helper(U, ...) [with U = boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>, T = boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>] /usr/local/include/boost/asio/read_until.hpp:58: note: static char boost::asio::detail::has_result_type<T>::helper(U, typename U::result_type*) [with U = boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>, T = boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>] /usr/local/include/boost/asio/read_until.hpp:60: error: enumerator value for `value' not integer constant ../src/temp.cpp: In constructor `MyClass::MyClass()': ../src/temp.cpp:56: error: no matching function for call to `read_until(boost::asio::serial_port&, boost::asio::streambuf&, boost::function<std::pair<boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, bool> ()(boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>, boost::asio::buffers_iterator<boost::asio::const_buffers_1, char>)>&)' ----temp.cpp #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> using namespace std; class MyClass { private: boost::asio::serial_port _port; boost::asio::io_service _service; boost::asio::streambuf _readBuffer; typedef boost::asio::buffers_iterator<boost::asio::streambuf::const_buffers_type> t_Iterator; typedef std::pair<t_Iterator, bool> t_ConditionPair; t_ConditionPair customCondition(t_Iterator i1, t_Iterator i2) { t_ConditionPair cond; return cond; } public: MyClass() : _port(_service, "/dev/ttyS0") { boost::function<t_ConditionPair(t_Iterator,t_Iterator)> cond = boost::bind( &MyClass::customCondition, this, _1, _2 ); boost::asio::read_until( _port, _readBuffer, cond ); }; virtual ~MyClass() { }; };
On Sat, Feb 20, 2010 at 10:56 AM, Igor R <boost.lists@gmail.com <mailto:boost.lists@gmail.com>> wrote:
> I'm having some trouble resolving the call to read_until > (see snippet below) > > Is there some reason I am not be able to use a boost::function > as the MatchCondition object?
It compiles well with MSVC9.0
As a workaround, try assigning the result of the bind to a boost::function<> object of the appropriate type first, and then passing that boost::function<> object by value into the asio method
Not sure if it will work, but if nothing else it might get the compiler to give you a different error and you can figure something out.
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG marty wrote:
Thanks for your input. Unfortunately; no dice. It still doesn't compile (below), and the error(also below) provides little insight in my relatively inexperienced assessment. I have a feeling that the enable_if mechanism is not behaving properly on my particular system.
It isn't the enable_if per se that is causing the problem. is_match_condition doesn't seem to work properly.
(the fact that others have successfully compiled this implies that the boost::function must have the correct signature to satisfy the enable_if....)
----error
/usr/local/include/boost/asio/read_until.hpp:60: error: enumerator value for `value' not integer constant ../src/temp.cpp: In constructor `MyClass::MyClass()':
The compiler doesn't seem to like the implementation of has_result_type here.
I'm following up my original post with some actual code an interested person might try to compile, as well as the specific errors I'm getting. boost 1.41.0, gcc 3.4.6 Can you use a more recent compiler?
It also /might/ work if you replace has_result_type with BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) and add #include <boost/mpl/has_xxx.hpp>. In Christ, Steven Watanabe
participants (4)
-
Igor R
-
marty
-
Steven Watanabe
-
Zachary Turner