|
Boost Users : |
Subject: [Boost-users] [phoenix] compile error using arg1
From: Paul Heil (paul.heil_at_[hidden])
Date: 2009-02-09 17:13:12
While expanding my horizons to include functional programming, I've run in
to a problem with boost::phoneix lambda functions. I'm trying to use a
for_each() command with an overloaded<< operator, but I can't seem to get
they types right, and I get a compile error:
test.cpp(147) : error C2679: binary '<<' : no operator found which takes a
right-hand operand of type 'const boost::phoenix::actor<Eval>' (or there is
no acceptable conversion)
I've seen example code that's very similiar to this using "cout" instead of
the overloaded << operator I have, so I tend to think this is possible. My
code is below, can anybody suggest what I could do to fix this?
using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
class A
{
public:
friend MSXML2::IXMLDOMNode* operator <<( MSXML2::IXMLDOMNode*
node, const A&
a );
private:
// ...
};
MSXML2::IXMLDOMNode* operator <<( MSXML2::IXMLDOMNode* node, const A& a )
{
// Add stuff from A to 'node'
return node;
}
int main()
{
MSXML2::IXMLDOMElementPtr pElem;
// MSXML2 DOM doc creation removed for brevity
std::list< A > theList;
// add items to the list...
// copy items from the list to the XML element
// This does not compile (C2679)
std::for_each( theList.begin(), theList.end(), pElem << arg1 );
return 0;
}
I realize I could write a proxy function like:
void A::Print( MSXML2::IXMLDOMNode* t ) const
{
t << *this;
};
and use the bind() within the for_each()
std::for_each( theList.begin(), theList.end(), bind( &A::Print, arg1,
pElem ) );
but, I'd like to avoid that if possible.
If anybody can suggest how to get this done, I would appreciate it.
Thanks,
PaulH
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