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
Paul Heil wrote:
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)
Did you include operator.hpp? Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
On Mon, Feb 9, 2009 at 8:13 PM, Joel de Guzman
Paul Heil wrote:
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)
Did you include operator.hpp?
Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
If by "operator.hpp", you mean "#include
participants (2)
-
Joel de Guzman
-
Paul Heil