RE: [boost] Lambda/functions

best2=bind(&Node::value2, bind( &std::vector<Node>::at, //Ask for an element bind(&Node::children,_1), //Get the vector object 0 ) //Ask for element zero );
[3]: function.cpp: In function `int main(int, char**)': function.cpp:69: no matching function for call to `bind(<unknown type>, const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_ba se<boost::lambda::action<2, boost::lambda::function_action<2, boost::lambda::detail::unspecified> >, boost::tuples::tuple<std::vector<Node, std::allocator<Node> > Node::*, const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, int)'
It's simple, compiler can't guess which function "at" you try to bind. See overloading section of lambda documentation. Hint: typedef std::vector<int> ints; typedef ints::const_reference ( ints::*ConstAtFunc ) (ints::size_type) const; Now call bind with ConstAtFunc( at ) as function Roman

best2=bind(&Node::value2, bind( &std::vector<Node>::at, //Ask for an element bind(&Node::children,_1), //Get the vector object 0 ) //Ask for element zero );
It's simple, compiler can't guess which function "at" you try to bind.
See overloading section of lambda documentation.
I couldn't see a section on overloading, or that dealt with this problem. Do you know the section number/title in the docs? Or perhaps it was an article somewhere else?
typedef std::vector<int> ints; typedef ints::const_reference ( ints::*ConstAtFunc ) (ints::size_type) const; Now call bind with ConstAtFunc( at ) as function
Thanks, that worked (and with operator[] as well): typedef std::vector<Node>::const_reference ( std::vector<Node>::*ConstVectorFunc ) (std::vector<Node>::size_type) const; best2=bind(&Node::value2, bind( ConstVectorFunc(&std::vector<Node>::at), bind(&Node::children,_1), 0 ) ); best2=bind(&Node::value2, bind( ConstVectorFunc(&std::vector<Node>::operator[]), bind(&Node::children,_1), 0 ) ); However I don't really understand what is going on. Is there a way to do this without using the typedef? I tried cref() around various parameters but cannot get that to compile. Darren
participants (2)
-
Darren Cook
-
Roman Yakovenko