|
Boost Users : |
Subject: Re: [Boost-users] boost::asio::read_until w/ boost::function
From: marty (marty_at_[hidden])
Date: 2010-02-23 15:32:43
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_at_[hidden]
> <mailto:boost.lists_at_[hidden]>> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net